Fundamentals/String Compression
← PrevNext →
Given a string s, compress it by replacing each run of consecutive identical characters with the character followed by the run's length. The output always includes the count, even when the run length is 1.
Input
s: a string
Output
The compressed string.
Examples
Example 1
Inputs = "hello"
Output"h1e1l2o1"
Example 2
Inputs = "abcde"
Output"a1b1c1d1e1"
Constraints
0 <= s.length <= 10^5.