class Solution: def largeGroupPositions(self, s: str) -> List[List[int]]: res = [] num = 1 for index, i in enumerate(s): a = s[index + 1] if index + 1 < len(s) else"" if s[index] == a: num += 1 else: if num >= 3: res.append([index - num + 1, index]) num = 1 return res
go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
func largeGroupPositions(s string) [][]int { num := 1 var res [][]int for index, i := range s { var next string if index + 1 < len(s) { next = string(s[index + 1]) } if string(i) == next { num += 1 } else { if num >= 3 { res = append(res, []int{index - num + 1, index}) } num = 1 } } return res }
func largeGroupPositions(s string) [][]int { cur, next := 0, 0 var res [][]int if len(s) <= 2 { return res } for { if next >= len(s) { break } for { if next < len(s) { if s[cur] == s[next] { next++ } else { break } } else { break } } if next - cur >= 3 { res = append(res, []int{cur, next-1}) } cur = next } return res }