Leetcode 830. Positions of Large Groups

class Solution:
    def largeGroupPositions(self, S: str) -> List[List[int]]:
        ans = []
        size = len(S)
        if size < 3:
            return []
        i = 0
        while i < size:
            length = 1
            j = i + 1
            while j < size and S[i] == S[j]:
                j += 1
                length += 1
            if length > 2:
                ans.append([i, j - 1])
            i = j
        return ans
        

猜你喜欢

转载自www.cnblogs.com/zywscq/p/10699810.html