String Compression
Run-length encode s: replace every run of the same letter by the letter followed by the length of the run, even when the run has length 1. Return the encoded string. An empty string encodes to an empty string.
Example 1
s "aaabcc"
returns "a3b1c2"
Runs aaa, b, cc become a3b1c2.
Constraints
0 <= len(s) <= 100shas lowercase letters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Subtract Digit StringsEasy
- Valid Calendar DateEasy
- Valid UsernameEasy
- Well-Formed SumEasy
- Add the FractionsMedium
- Count and SayMedium
- Expand Character RangesMedium
- Falling DominoesMedium