class Solution:
def compressString(self , s ):
if not s: return ''
N = len(s)
ret = []
l, r = 0, 0
while r <= N: # r 需要遍历到最后一个字符的下一个位置
# 当不满足条件时,直接移动 l 到 r,不需要 while 判断
if r == N or s[l] != s[r]: # 注意判断顺序
ret.append(s[l])
if r > l + 1:
ret.append(str(r - l))
l = r
r += 1
return ''.join(ret)