【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   鹅要长大  阅读(180)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示