Skip to content

Commit 40a39a1

Browse files
solves positions of large groups
1 parent 7b3b774 commit 40a39a1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LeetCode Algorithms
22

3-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-192/2081-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-192/2081-1abc9c.svg)
3+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-193/2081-1f425f.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-193/2081-1abc9c.svg)
55
![problems-solved-python](https://img.shields.io/badge/Python-186/2081-1abc9c.svg)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
@@ -223,7 +223,7 @@
223223
| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | [![Java](assets/java.png)](src/MostCommonWord.java) |
224224
| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | [![Java](assets/java.png)](src/ShortestDistanceToACharacter.java) |
225225
| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | [![Java](assets/java.png)](src/GoatLatin.java) |
226-
| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | |
226+
| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | [![Java](assets/java.png)](src/PositionsOfLargeGroups.java) |
227227
| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | |
228228
| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | |
229229
| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | |

src/PositionsOfLargeGroups.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
public class PositionsOfLargeGroups {
5+
public List<List<Integer>> largeGroupPositions(String s) {
6+
List<List<Integer>> result = new ArrayList<>();
7+
char current = s.charAt(0);
8+
int start = 0;
9+
for (int index = 1 ; index < s.length() ; index++) {
10+
if (s.charAt(index) != current) {
11+
if (index - start >= 3) result.add(List.of(start, index - 1));
12+
start = index;
13+
current = s.charAt(index);
14+
}
15+
}
16+
if (s.length() - start >= 3) result.add(List.of(start, s.length() - 1));
17+
return result;
18+
}
19+
}

0 commit comments

Comments
 (0)