class Solution { public List> largeGroupPositions(String S) { List> ls = new LinkedList>(); for (int i = 0; i < S.length() - 2; i++) { if (S.charAt(i) == S.charAt(i + 1) && S.charAt(i) == S.charAt(i + 2)) { char s = S.charAt(i); List l = new LinkedList(); int a = i; int b = i; while (b<S.length()&&s == S.charAt(b)) { b++; } l.add(a); l.add(b-1); ls.add(l); i = b-1; } } return ls; } }