【Leetcode_easy】830. Positions of Large Groups

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;

 

posted on 2019-07-19 17:56  鹅要长大  阅读(179)  评论(0编辑  收藏  举报

导航