830. Positions of Large Groups

class Solution {
public:
    vector<vector<int>> largeGroupPositions(string s) {
        vector<vector<int>> res;
        int start = 0, end = 0;
        for (int i = 1; i < s.length(); i++) {
            if (s[i] == s[start]) {
                end = i;
            }
            else {
                if (end - start + 1 >= 3) {
                    vector<int> t;
                    t.push_back(start);
                    t.push_back(end);
                    res.push_back(t);
                }
                start = i;
                end = i;
            }
        }
        if (end - start + 1 >= 3) {
            vector<int> t;
            t.push_back(start);
            t.push_back(end);
            res.push_back(t);
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/JTechRoad/p/9995381.html