Scan runs of the same character. Write the character once, then its count if the run is longer than one. A read pointer finds runs; a write pointer lays down the compressed result.
Try:
chars — overwritten in place (write pointer ◂, read run highlighted)