830. Positions of Large Groups
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 53% Topics: String
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def largeGroupPositions(self, S):
"""
:type S: str
:rtype: List[List[int]]
"""
result = []
i = 0
for j in xrange(len(S)):
if j == len(S)-1 or S[j] != S[j+1]:
if j-i+1 >= 3:
result.append([i, j])
i = j+1
return result
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions