File tree 1 file changed +11
-26
lines changed
1 file changed +11
-26
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
- public List <List <Integer >> largeGroupPositions (String S ) {
3
- List <List <Integer >> positions = new ArrayList <>();
4
-
5
- int i = 1 ;
6
- int count = 1 ;
7
- int start = 0 ;
8
-
9
- while (i < S .length ()) {
10
- if (S .charAt (i ) == S .charAt (i -1 )) {
11
- count ++;
2
+ public List <List <Integer >> largeGroupPositions (String s ) {
3
+ List <List <Integer >> result = new ArrayList <>();
4
+ int idx = 0 ;
5
+ while (idx < s .length ()) {
6
+ int startIdx = idx ;
7
+ char c = s .charAt (idx );
8
+ while (idx < s .length () && s .charAt (idx ) == c ) {
9
+ idx ++;
12
10
}
13
- else {
14
- if (count >= 3 ) {
15
- List <Integer > temp = Arrays .asList (start , i -1 );
16
- positions .add (temp );
17
- }
18
-
19
- start = i ;
20
- count = 1 ;
11
+ if (idx - startIdx >= 3 ) {
12
+ result .add (Arrays .asList (startIdx , idx - 1 ));
21
13
}
22
-
23
- i ++;
24
14
}
25
-
26
- if (count >= 3 ) {
27
- positions .add (Arrays .asList (start , i -1 ));
28
- }
29
-
30
- return positions ;
15
+ return result ;
31
16
}
32
17
}
You can’t perform that action at this time.
0 commit comments