i
and res
to 0.i
is less than the length of chars
:
a. Set groupLength
to 1.
b. While the next character is the same as chars[i]
, increment groupLength
and i
.
c. Write the character chars[i]
to chars[res]
and increment res
.
d. If groupLength
is greater than 1, convert groupLength
to a string and write each digit to chars[res]
incrementing res
for each digit written.
e. Increment i
to move to the next group of characters.res
as the new length of the array.