Leetcode Note: Go - Positions of Large Groups
Positions of Large Groups - LeetCode
https://leetcode.com/problems/positions-of-large-groups/
- Go 言語で取り組んだメモ
所感
- string s が渡されるので s に含まれる連続した文字の開始位置と終了位置を int 配列で return する
回答
Positions of Large Groups - LeetCode
https://leetcode.com/problems/positions-of-large-groups/solution/
One pass with golang - LeetCode Discuss
https://leetcode.com/problems/positions-of-large-groups/discuss/2462092/One-pass-with-golang
func largeGroupPositions(s string) [][]int {
s = s + " "
var res [][]int
left := 0
for right := 1; right < len(s); right ++ {
if s[right] != s[right-1] {
if right - left >= 3 {
res = append(res, []int{left, right-1})
}
left = right
}
}
return res
}