题目描述:
In a string S
of lowercase letters, these letters form consecutive groups of the same character.
For example, a string like S = "abbxxxxzyy"
has the groups "a"
, "bb"
, "xxxx"
, "z"
and "yy"
.
Call a group large if it has 3 or more characters. We would like the starting and ending positions of every large group.
The final answer should be in lexicographic order.
Example 1:
Input: "abbxxxxzzy"Output: [[3,6]]Explanation: "xxxx" is the single large group with starting 3 and ending positions 6.
Example 2:
Input: "abc"Output: []Explanation: We have "a","b" and "c" but no large group.
Example 3:
Input: "abcdddeeeeaabbbcd"Output: [[3,5],[6,9],[12,14]]
Note: 1 <= S.length <= 1000
要完成的函数:
vector<vector<int>> largeGroupPositions(string S)
说明:
1、给定一个字符串S,如果一个字符连续出现三次及三次以上,那么它就是一个“大组合”,要求找出所有“大组合”的起始位置和结束位置,最终以vector<vector<int>>的形式返回。
2、明白题意,这又是一道简单题。
直接贴上代码(附详解),如下:
vector> largeGroupPositions(string S) { int s1=S.size(),i=0,j; vector >res;//最后返回的vector vector res1;//子vector while(i
上述代码实测13ms,因为服务器接收到的cpp submissions有限,所以没有打败的百分比。