(String str)
| 52 | } |
| 53 | |
| 54 | public static String compressBetter(String str) { |
| 55 | int size = countCompression(str); |
| 56 | if (size >= str.length()) { |
| 57 | return str; |
| 58 | } |
| 59 | StringBuffer mystr = new StringBuffer(); |
| 60 | char last = str.charAt(0); |
| 61 | int count = 1; |
| 62 | for (int i = 1; i < str.length(); i++) { |
| 63 | if (str.charAt(i) == last) { |
| 64 | count++; |
| 65 | } else { |
| 66 | mystr.append(last); |
| 67 | mystr.append(count); |
| 68 | last = str.charAt(i); |
| 69 | count = 1; |
| 70 | } |
| 71 | } |
| 72 | mystr.append(last); |
| 73 | mystr.append(count); |
| 74 | return mystr.toString(); |
| 75 | } |
| 76 | |
| 77 | public static String compressAlternate(String str) { |
| 78 | int size = countCompression(str); |
no test coverage detected