Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 42a8a36

Browse files
🐱(array): 830. 较大分组的位置
1 parent ab41c10 commit 42a8a36

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎docs/data-structure/array/README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,6 +2935,32 @@ func getMin(a int, b int) int {
29352935
}
29362936
```
29372937

2938+
## 830. 较大分组的位置
2939+
2940+
[原题链接](https://leetcode-cn.com/problems/positions-of-large-groups/)
2941+
2942+
### 顺序遍历
2943+
2944+
判断前后两个连续字母是否相同,若字母连续且当前字母连续出现次数已 >=3,那么加入结果集中。
2945+
2946+
```python
2947+
class Solution:
2948+
def largeGroupPositions(self, s: str) -> List[List[int]]:
2949+
length = len(s)
2950+
ans = []
2951+
count = 1
2952+
for i in range(length):
2953+
if i == length - 1 or s[i] != s[i + 1]:
2954+
# 出现不连续字母
2955+
if count >= 3:
2956+
ans.append([i - count + 1, i])
2957+
count = 1
2958+
else:
2959+
count += 1
2960+
2961+
return ans
2962+
```
2963+
29382964
## 914. 卡牌分组
29392965

29402966
[原题链接](https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /