-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargeGroupPositions.java
More file actions
32 lines (28 loc) · 1 KB
/
Copy pathLargeGroupPositions.java
File metadata and controls
32 lines (28 loc) · 1 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
package LeetcodePractice;
import java.util.ArrayList;
import java.util.List;
public class LargeGroupPositions {
public List<List<Integer>> largeGroupPositions(String s) {
List<List<Integer>> result = new ArrayList<>();
int n = s.length();
int start = 0;
for (int i = 1; i <= n; i++) {
if (i == n || s.charAt(i) != s.charAt(start)) {
if (i - start >= 3) {
List<Integer> interval = new ArrayList<>();
interval.add(start);
interval.add(i - 1);
result.add(interval);
}
start = i;
}
}
return result;
}
public static void main(String[] args) {
LargeGroupPositions sol = new LargeGroupPositions();
System.out.println(sol.largeGroupPositions("abbxxxxzzy"));
System.out.println(sol.largeGroupPositions("abc"));
System.out.println(sol.largeGroupPositions("abcdddeeeeaabbbcd"));
}
}