forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_830.java
26 lines (24 loc) · 760 Bytes
/
_830.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
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class _830 {
public static class Solution1 {
public List<List<Integer>> largeGroupPositions(String S) {
List<List<Integer>> result = new ArrayList<>();
char[] chars = S.toCharArray();
for (int i = 0; i < chars.length; ) {
char first = chars[i];
int j = i + 1;
while (j < chars.length && first == chars[j]) {
j++;
}
if ((j - i) >= 3) {
result.add(Arrays.asList(i, j - 1));
}
i = j;
}
return result;
}
}
}