Golang Leetcode 830. Positions of Large Groups.go

2019-05-05 11:52:34 浏览数 (1)

版权声明:原创勿转 https://cloud.tencent.com/developer/article/1420467

思路

直接按照题目的意思求解

code

代码语言:javascript复制
func largeGroupPositions(S string) [][]int {
	ret := [][]int{}
	i, j := 0, 0
	for i < len(S) {
		for j < len(S) && S[i] == S[j] {
			j  
		}
		if j-i >= 3 {
			tmp := []int{i, j - 1}
			ret = append(ret, tmp)
		}
		i = j
	}
	return ret
}

0 人点赞