【LeetCode】830. Positions of Large Groups

版权声明:本文为博主原创文章,请尊重原创,转载请注明原文地址和作者信息! https://blog.csdn.net/zzc15806/article/details/82421097

class Solution:
    # 遍历字符串
    def largeGroupPositions(self, S):
        """
        :type S: str
        :rtype: List[List[int]]
        """
        size = len(S)
        cnt = 1
        lg = []
        for i in range(size-1):
            if S[i+1] == S[i]:
                cnt += 1
            else:
                if cnt >= 3:
                    lg.append([i-cnt+1, i]) 
                cnt = 1
        if cnt >= 3:
            lg.append([size-cnt, size-1])
        return lg

猜你喜欢

转载自blog.csdn.net/zzc15806/article/details/82421097