Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun compress2(s: String): String {
- val sb = StringBuilder()
- var l = 0
- var r = 0
- while (l < s.length) {
- while (r < s.length && s[l] == s[r]) r++
- sb.append(s[l])
- if(r - l > 1) sb.append(r - l)
- l = r
- }
- return sb.toString()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement