• 문제 링크
Positions of Large Groups - LeetCode
Can you solve this real interview question? Positions of Large Groups - In a string s of lowercase letters, these letters form consecutive groups of the same character. For example, a string like s = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z", and
leetcode.com
• 풀이 코드
import java.util.ArrayList;
import java.util.List;
public class Solution {
public List<List<Integer>> largeGroupPositions(String s) {
List<List<Integer>> res = new ArrayList<>();
for (int i = 0, j = 0, n = s.length(); i < n; i++) {
if (i == n - 1 || s.charAt(i) != s.charAt(i + 1)) {
if (i - j + 1 >= 3) res.add(List.of(j, i));
j = i + 1;
}
}
return res;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 836. Rectangle Overlap - Java (0) | 2026.10.24 |
|---|---|
| [LeetCode] 832. Flipping an Image - Java (0) | 2026.10.23 |
| [LeetCode] 824. Goat Latin - Java (0) | 2026.10.21 |
| [LeetCode] 821. Shortest Distance to a Character - Java (0) | 2026.10.20 |
| [LeetCode] 819. Most Common Word - Java (0) | 2026.10.19 |
댓글