-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path830.java
More file actions
46 lines (41 loc) · 1.44 KB
/
830.java
File metadata and controls
46 lines (41 loc) · 1.44 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
__________________________________________________________________________________________________
sample 1 ms submission
class Solution {
public List<List<Integer>> largeGroupPositions(String S) {
List<List<Integer>> res = new ArrayList();
int i = 0,N = S.length();
for(int j = 0;j < N;j++){
if(j == N-1 || S.charAt(j)!=S.charAt(j+1)){
if(j - i + 1 >=3){
res.add(Arrays.asList(new Integer[]{i,j}));
}
i = j + 1;
}
}
return res;
}
}
__________________________________________________________________________________________________
sample 37332 kb submission
class Solution {
public List<List<Integer>> largeGroupPositions(String S) {
List<List<Integer>> res = new ArrayList<>();
for (int i = 0; i< S.length(); i++){
List<Integer> list = new ArrayList<>();
int j = i+1;
while (j < S.length() && S.charAt(j) == S.charAt(i)){
j++;
}
if (j-1 - i>= 2){
list.add(i);
list.add(j-1);
res.add(list);
i = j -1;
} else{
continue;
}
}
return res;
}
}
__________________________________________________________________________________________________