compressString("aaabbbbbcccc") --> a3b5c4
compressString("aabbbbccc") --> a2b4c3
compressString("abc") --> abc
String
, copying characters to a new StringBuilder
object along with the repeat counts.Character
and the other to store its count. Initialize the last Character
with first element in the Array
and set its count to 1.StringBuilder
object, to store the compressed output.Array
of Character
s . If the Character
at each position is equal to last Character
, increment the count. Otherwise, change the last Character
and initialize its count to 1.Character
and its count.
public static String compressString(String text) { }
C
Java
Python