Movatterモバイル変換


[0]ホーム

URL:


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

Commit74cf4bf

Browse files
author
Sathish Babu
committed
✨ Added solution to 830
1 parentf099aa0 commit74cf4bf

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

‎src/0830.Positions-of-Large-Groups/README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,35 @@
55
66
##Description
77

8+
In a string S of lowercase letters, these letters form consecutive groups of the same character.
9+
10+
For example, a string like S = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z" and "yy".
11+
12+
Call a group large if it has 3 or more characters. We would like the starting and ending positions of every large group.
13+
14+
The final answer should be in lexicographic order.
15+
816
**Example 1:**
917

1018
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
19+
Input: "abbxxxxzzy"
20+
Output: [[3,6]]
21+
Explanation: "xxxx" is the single large group with starting 3 and ending positions 6.
22+
```
23+
24+
**Example 2:**
25+
26+
```
27+
Input: "abc"
28+
Output: []
29+
Explanation: We have "a","b" and "c" but no large group.
30+
```
31+
32+
**Example 3:**
33+
34+
```
35+
Input: "abcdddeeeeaabbbcd"
36+
Output: [[3,5],[6,9],[12,14]]
1337
```
1438

1539
##题意
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(Sstring) [][]int {
4+
n:=len(S)
5+
ifn<3 {
6+
return [][]int{}
7+
}
8+
res:=make([][]int,0)
9+
c,l,r:=1,-1,-1
10+
fori:=1;i<n;i++ {
11+
ifS[i]==S[i-1] {
12+
c++
13+
ifl==-1 {
14+
l=i-1
15+
}
16+
ifc>=3 {
17+
r=i
18+
}
19+
}else {
20+
ifc>=3 {
21+
res=append(res, []int{l,r})
22+
}
23+
c,l=1,-1
24+
}
25+
}
26+
ifc>=3 {
27+
res=append(res, []int{l,r})
28+
}
29+
returnres
530
}

‎src/0830.Positions-of-Large-Groups/Solution_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
14-
expectbool
13+
inputsstring
14+
expect[][]int
1515
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
16+
{"TestCase","abbxxxxzzy", [][]int{{3,6}}},
17+
{"TestCase","abcdddeeeeaabbbcd", [][]int{{3,5}, {6,9}, {12,14}}},
18+
{"TestCase","ab", [][]int{}},
19+
{"TestCase","xxxaaaa", [][]int{{0,2}, {3,6}}},
1920
}
2021

2122
//开始测试

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp