-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
31 lines (29 loc) · 976 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public List<List<Integer>> largeGroupPositions(String S) {
Character lastCharacter = null;
List<List<Integer>> res = new ArrayList<List<Integer>>();
int start = 0,
end = 0;
for (int i = 0; i < S.length(); i++) {
if (lastCharacter == null || lastCharacter.equals(S.charAt(i))) {
end = i;
} else {
if (end - start + 1 >= 3) {
List<Integer> group = new ArrayList<Integer>();
group.add(start);
group.add(end);
res.add(group);
}
end = start = i;
}
lastCharacter = S.charAt(i);
}
if (end - start + 1 >= 3) {
List<Integer> group = new ArrayList<Integer>();
group.add(start);
group.add(end);
res.add(group);
}
return res;
}
}