Run-Length Compression

Start Timer

0:00:00

Upvote
6
Downvote
Save question
View comments

Write a function called compress_string that takes a string of lowercase letters and compresses each run of identical characters into the character followed by its count, in order.

If a character appears only once in a run, omit the count.

Example:

Input:

s = 'aaaaabccccdd'

Output:

compress_string(s) -> 'a5bc4d2'
.
.
.
.
.


Comments

Loading comments