Tell me how to improve the existing code:
public class RLE { public static String encode(String s) { if (s == "" || s == null) return ""; StringBuilder sb = new StringBuilder(); int count = 1; char previous = s.charAt(0); char current; for (int i = 1; i < s.length(); i++) { current = s.charAt(i); if (current == previous) { count++; } else { if (count == 1) { sb.append(previous); } else if (count > 1) { sb.append(count).append(previous); count = 1; } } previous = current; } return sb.toString(); } Now the result of the compression 'Heeeeeeeeeeeellooooo' -> H12e2l
The expected result with the condition: the number of letters in the repetition is more than nine, there must be two combinations of the letter number 'Heeeeeeeeeeeellooooo' -> H9e3e2l5o
if (s == "" || s == null) return "";if (s == null || "".equals(s)) return "";- JVicif (current == previous)add toif ((current == previous) && (count < 9))? - Akina