Skip to content

Commit fea37c8

Browse files
committedFeb 18, 2025
Add solution #830
1 parent 9d00d53 commit fea37c8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@
366366
821|[Shortest Distance to a Character](./0821-shortest-distance-to-a-character.js)|Easy|
367367
824|[Goat Latin](./0824-goat-latin.js)|Easy|
368368
827|[Making A Large Island](./0827-making-a-large-island.js)|Hard|
369+
830|[Positions of Large Groups](./0830-positions-of-large-groups.js)|Easy|
369370
831|[Masking Personal Information](./0831-masking-personal-information.js)|Medium|
370371
841|[Keys and Rooms](./0841-keys-and-rooms.js)|Medium|
371372
844|[Backspace String Compare](./0844-backspace-string-compare.js)|Easy|
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* 830. Positions of Large Groups
3+
* https://leetcode.com/problems/positions-of-large-groups/
4+
* Difficulty: Easy
5+
*
6+
* In a string s of lowercase letters, these letters form consecutive groups of the same character.
7+
*
8+
* For example, a string like s = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z", and "yy".
9+
*
10+
* A group is identified by an interval [start, end], where start and end denote the start and end
11+
* indices (inclusive) of the group. In the above example, "xxxx" has the interval [3,6].
12+
*
13+
* A group is considered large if it has 3 or more characters.
14+
*
15+
* Return the intervals of every large group sorted in increasing order by start index.
16+
*/
17+
18+
/**
19+
* @param {string} s
20+
* @return {number[][]}
21+
*/
22+
var largeGroupPositions = function(s) {
23+
const result = [];
24+
let start = 0;
25+
26+
for (let i = 1; i <= s.length; i++) {
27+
if (s.length === i || s[i] !== s[start]) {
28+
if (i - start >= 3) {
29+
result.push([start, i - 1]);
30+
}
31+
start = i;
32+
}
33+
}
34+
35+
return result;
36+
};

0 commit comments

Comments
 (0)
Please sign in to comment.