2021-01-04 830.较大分组的位置

830.较大分组的位置

思路一:

直接按照题目意思一个个排查过去

class Solution {
    
    
    public List<List<Integer>> largeGroupPositions(String s) {
    
    
        List<List<Integer>> res = new LinkedList<List<Integer>>();
        int i=0;
        while(i<s.length()){
    
    
            int start = i;
            int end = i;
            char tmpC = s.charAt(i);
            i++; //此时end依旧是i,我们的end指向的永远是包含的最后一个元素!
            while(i<s.length() && s.charAt(i)==tmpC){
    
    
                end++;
                i++;
            }
            // System.out.println("["+start+","+end+"]");

            if((end-start+1)>=3){
    
    
                List<Integer> tmp = new LinkedList<Integer>();
                tmp.add(start);
                tmp.add(end);
                res.add(tmp);
                // System.out.println(s.charAt(start));
            }
        }

        return res;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_44495738/article/details/112211516