class Solution { public int compress(char[] chars) { // https://leetcode.com/problems/string-compression/solution/ int anchor = 0, write = 0; for (int read = 0; read anchor) { for (char c: ("" + (read - anchor + 1)).toCharArray()) { chars[write++] = c; } } anchor = read + 1; } } return write; } }