本文共 524 字,大约阅读时间需要 1 分钟。
class Solution: def countLetters(self, s: str) -> int: container = [] j = 0 i = 0 while i < len(s): j = i while i < len(s)-1 and s[i] == s[i+1]: i += 1 container.append(s[j:i+1]) i += 1 def plus(n): res = 0 while n>=1: res += n n -= 1 return res res = 0 for sustr in container: res += plus(len(sustr)) return res
转载地址:http://hijii.baihongyu.com/