Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit f8b16ba

Browse files
committed
984 added
1 parent 5a013bc commit f8b16ba

File tree

4 files changed

+95
-3
lines changed

4 files changed

+95
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# [984. String Without AAA or BBB](https://leetcode.com/problems/string-without-aaa-or-bbb/)
2+
3+
Given two integers A and B, return any string S such that:
4+
5+
S has length A + B and contains exactly A 'a' letters, and exactly B 'b' letters;
6+
The substring 'aaa' does not occur in S;
7+
The substring 'bbb' does not occur in S.
8+
9+
Example 1:
10+
11+
```text
12+
Input: A = 1, B = 2
13+
Output: "abb"
14+
Explanation: "abb", "bab" and "bba" are all correct answers.
15+
```
16+
17+
Example 2:
18+
19+
```text
20+
Input: A = 4, B = 1
21+
Output: "aabaa"
22+
23+
Note:
24+
25+
- 0 <= A <= 100
26+
- 0 <= B <= 100
27+
- It is guaranteed such an S exists for the given A and B.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0984
2+
3+
func strWithout3a3b(A int, B int) string {
4+
5+
return ""
6+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package problem0984
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
A int
13+
B int
14+
ans string
15+
}{
16+
17+
{
18+
1,
19+
2,
20+
"abb",
21+
},
22+
23+
{
24+
4,
25+
1,
26+
"aabaa",
27+
},
28+
29+
// 可以有多个 testcase
30+
}
31+
32+
func isCorrect(A, B int, s string) bool {
33+
if A+B != len(s) ||
34+
len(strings.Replace(s, "a", "", -1)) != B ||
35+
len(strings.Replace(s, "b", "", -1)) != A {
36+
return false
37+
}
38+
if strings.Contains(s, "aaa") ||
39+
strings.Contains(s, "bbb") {
40+
return false
41+
}
42+
return true
43+
}
44+
45+
func Test_strWithout3a3b(t *testing.T) {
46+
ast := assert.New(t)
47+
48+
for _, tc := range tcs {
49+
ast.True(isCorrect(tc.A, tc.B, strWithout3a3b(tc.A, tc.B)))
50+
}
51+
}
52+
53+
func Benchmark_strWithout3a3b(b *testing.B) {
54+
for i := 0; i < b.N; i++ {
55+
for _, tc := range tcs {
56+
strWithout3a3b(tc.A, tc.B)
57+
}
58+
}
59+
}

leetcode.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 927,
4-
"Updated": "2019-02-03T13:08:58.697681697+08:00",
4+
"Updated": "2019-02-03T13:23:43.339935459+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 210,
@@ -11845,7 +11845,7 @@
1184511845
"ID": 985,
1184611846
"Title": "Sum of Even Numbers After Queries",
1184711847
"TitleSlug": "sum-of-even-numbers-after-queries",
11848-
"PassRate": "68%",
11848+
"PassRate": "69%",
1184911849
"Difficulty": "Easy",
1185011850
"IsAccepted": false,
1185111851
"IsPaid": false,
@@ -11869,7 +11869,7 @@
1186911869
"ID": 987,
1187011870
"Title": "Vertical Order Traversal of a Binary Tree",
1187111871
"TitleSlug": "vertical-order-traversal-of-a-binary-tree",
11872-
"PassRate": "29%",
11872+
"PassRate": "30%",
1187311873
"Difficulty": "Medium",
1187411874
"IsAccepted": false,
1187511875
"IsPaid": false,

0 commit comments

Comments
 (0)