problem
830. Positions of Large Groups
solution1:
class Solution { public: vector<vector<int>> largeGroupPositions(string S) { vector<vector<int>> res; int start = 0, end = 0; for(int i=1; i<S.size(); ++i) { if(S[i]==S[i-1]) end = i; else if(S[i]!=S[i-1]) { if(end-start>=2) res.push_back({start, end}); start = i; end = i; } } if(S.back()==S[S.size()-2] && end-start>=2) res.push_back({start, end});//err... return res; } };
参考
1. Leetcode_easy_830. Positions of Large Groups;
2. grandyang;
完