# 830.Position of Large Groups

**830. Position of Large Groups**

> 题目难度 Easy

> 在一个由小写字母构成的字符串 S 中，包含由一些连续的相同字符所构成的分组。 例如，在字符串 S = "abbxxxxzyy" 中，就含有 "a", "bb", "xxxx", "z" 和 "yy" 这样的一些分组。 我们称所有包含大于或等于三个连续字符的分组为较大分组。找到每一个较大分组的起始和终止位置。 最终结果按照字典顺序输出。

```
示例 1:
输入: "abbxxxxzzy"
输出: [[3,6]]
解释: "xxxx" 是一个起始于 3 且终止于 6 的较大分组。
示例 2:
输入: "abc"
输出: []
解释: "a","b" 和 "c" 均不是符合要求的较大分组。
示例 3:
输入: "abcdddeeeeaabbbcd"
输出: [[3,5],[6,9],[12,14]]
说明:  1 <= S.length <= 1000
```

方法: 比较简单，直接遍历一遍string，然后如果有两个相同，继续向后找，最后遇到不同的，求出长度，如果大于3，则压入向量中。

```
class Solution {
public:
    vector<vector<int>> largeGroupPositions(string S) {
        vector<vector<int>> result;
        size_t len=S.length();
        for(int i=0;i<len-1;i++)
        {
            if(S[i] == S[i+1])
            {
                int x=i++,y=x;
                while(S[i] ==S[i+1] && i<len-1)
                {
                    y=++i;
                }
                if(y-x >=2)
                {
                    vector<int > tmp;
                    tmp.push_back(x);
                    tmp.push_back(y);
                    result.push_back(tmp);
            }
            }

        }
        return result;


    }
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/830.position_of_large_groups.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
