classSolution { public List<List<Integer>> largeGroupPositions(String s) { List<List<Integer>> ans = newArrayList(); inti=0, N = s.length(); // i is the start of each group for (intj=0; j < N; ++j) { if (j == N-1 || s.charAt(j) != s.charAt(j+1)) { //双指针法,判断条件更好更完善,不相等或者到达尾端时 // Here, [i, j] represents a group. if (j-i+1 >= 3) ans.add(Arrays.asList(newInteger[]{i, j})); //i从j的下一个作为起始位置,相当于固定i,用j去遍历 i = j + 1; } } return ans; } }