(String str)
| 14 | } |
| 15 | |
| 16 | public static int countCompression(String str) { |
| 17 | if (str == null || str.isEmpty()) return 0; |
| 18 | char last = str.charAt(0); |
| 19 | int size = 0; |
| 20 | int count = 1; |
| 21 | for (int i = 1; i < str.length(); i++) { |
| 22 | if (str.charAt(i) == last) { |
| 23 | count++; |
| 24 | } else { |
| 25 | last = str.charAt(i); |
| 26 | size += 1 + String.valueOf(count).length(); |
| 27 | count = 1; |
| 28 | } |
| 29 | } |
| 30 | size += 1 + String.valueOf(count).length(); |
| 31 | return size; |
| 32 | } |
| 33 | |
| 34 | public static String compressBad(String str) { |
| 35 | int size = countCompression(str); |
no test coverage detected