Positions of Large Groups

找到一个string上连续长度超过3个同样字符的位置. 返回的是index.

class Solution {
    public List<List<Integer>> largeGroupPositions(String S) {
        List<List<Integer>> res = new ArrayList<>();
        int i = 0;
        while(i < S.length()) {
            List<Integer> cur = new ArrayList<>();
            char c = S.charAt(i);
            cur.add(i); // add start position first
            while(i < S.length() && S.charAt(i) == c)
                i++;
            if(i - cur.get(0) > 2) {
                cur.add(i-1);//add end position only if it is a large group
                res.add(cur);
            }
        }
        return res;
    }
}