#3163
String Compression III
specialist · 610 · lc medium +29 · 67% accepted · 633 likes · top 73%
Description
Given a string word, build its compression by repeatedly: taking the longest same-character prefix of up to 9 characters, removing it from word, and appending its length followed by the character to the result. Return the compressed string.
Code
1
2
3