Leetcode_830_较大分组的位置_水题

1/5

class Solution {
     
    public List<List<Integer>> largeGroupPositions(String s) {
     
        int st = 0;
        List<List<Integer>> ans = new LinkedList<>();
        for (int i = 1; i < s.length(); i++) {
     
            if (s.charAt(i) != s.charAt(i - 1)) {
     
                if (i - st >= 3) {
     
                   ans.add(Arrays.asList(st, i-1));
                }
                st = i;
            }
        }
        if(s.length()-st>=3){
     
            ans.add(Arrays.asList(st, s.length()-1));
        }
        return ans;
    }
}

你可能感兴趣的:(daily_algorithm,水题)