题目:
题解:
class Solution:def compress(self, chars: List[str]) -> int:def reverse(left: int, right: int) -> None:while left < right:chars[left], chars[right] = chars[right], chars[left]left += 1right -= 1n = len(chars)write = left = 0for read in range(n):if read == n - 1 or chars[read] != chars[read + 1]:chars[write] = chars[read]write += 1num = read - left + 1if num > 1:anchor = writewhile num > 0:chars[write] = str(num % 10)write += 1num //= 10reverse(anchor, write - 1)left = read + 1return write