Created
May 8, 2018 21:33
-
-
Save BiruLyu/6c0588ca4b647c10bc417036cde5e19f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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