class Solution { public int compress(char[] chars) { if(chars.length == 0) return -1; int start = 0; for(int end = 0, count = 0; end < chars.length; end++) { count++; if(end == chars.length-1 || chars[end] != chars[end + 1] ) { //We have found a difference or we are at the end of array chars[start] = chars[end]; // Update the character at start pointer start++; if(count != 1) { // Copy over the character count to the array char[] arr = String.valueOf(count).toCharArray(); for(int i=0;i