1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public: vector<vector<int>> largeGroupPositions(string s) { char prev = ' '; int start = -1, i = 0; vector<vector<int>> ans; for (char c : s) { if (c != prev) { if (i - start >= 3) { ans.push_back(vector<int>{start, i - 1}); } prev = c; start = i; } ++i; } if (i - start >= 3) ans.push_back(vector<int>{start, i - 1}); return ans; } };
|