Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BiruLyu/6c0588ca4b647c10bc417036cde5e19f to your computer and use it in GitHub Desktop.
Save BiruLyu/6c0588ca4b647c10bc417036cde5e19f to your computer and use it in GitHub Desktop.
class Solution {
public List<List<Integer>> largeGroupPositions(String S) {
List<List<Integer>> res = new ArrayList<>();
int len = S.length();
if (len < 3) return res;
int start = 0, end = 1;
while (end < len) {
while (end < len && S.charAt(end) == S.charAt(end - 1)) {
end++;
}
if (end - start >= 3) {
res.add(new ArrayList<>(Arrays.asList(start, end - 1)));
}
start = end;
end = end + 1;
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment