Compress Repeated Runs
Run-length encoding is useful when a string has many identical characters in a row: instead of storing the whole run, you store its length and the character. The function rle_encode receives a string s and replaces each consecutive run of the same character with the number of repetitions followed by that character. For example, aaabbc becomes 3a2b1c.
Примеры
Ввод
"aaabbc"Вывод
"3a2b1c"Ввод
"aaaaa"Вывод
"5a"Ввод
"abc"Вывод
"1a1b1c"Нужно реализовать
def rle_encode(s: str) -> str:
Теги
strings
Pieslēdzies, lai redzētu iesniegumu vēsturi
PieslēgtiesPieslēdzies, lai izmantotu AI mentoru
PieslēgtiesTests12
Visible tests
Slēptais tests 7
Slēptais tests 8
Slēptais tests 9
Slēptais tests 10
Slēptais tests 11
Slēptais tests 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid