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

Commit 611f7de

Browse files
committed
984 wrong answer
1 parent f8b16ba commit 611f7de

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
package problem0984
22

3+
import "strings"
4+
35
func strWithout3a3b(A int, B int) string {
6+
var sb strings.Builder
7+
sb.Grow(A + B)
8+
9+
a, b := 'a', 'b'
10+
if A < B {
11+
A, B = B, A
12+
a, b = b, a
13+
}
14+
15+
for A > 0 || B > 0 {
16+
for i := 2; i > 0 && A > 0; i-- {
17+
sb.WriteRune(a)
18+
A--
19+
}
20+
for i := 2; i > 0 && B > 0; i-- {
21+
sb.WriteRune(b)
22+
B--
23+
}
24+
}
425

5-
return ""
26+
return sb.String()
627
}

Algorithms/0984.string-without-aaa-or-bbb/string-without-aaa-or-bbb_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ var tcs = []struct {
2020
"abb",
2121
},
2222

23+
{
24+
1,
25+
3,
26+
"bbab",
27+
},
28+
2329
{
2430
4,
2531
1,
2632
"aabaa",
2733
},
2834

35+
{
36+
2,
37+
5,
38+
"bbabbab",
39+
},
40+
2941
// 可以有多个 testcase
3042
}
3143

@@ -46,7 +58,8 @@ func Test_strWithout3a3b(t *testing.T) {
4658
ast := assert.New(t)
4759

4860
for _, tc := range tcs {
49-
ast.True(isCorrect(tc.A, tc.B, strWithout3a3b(tc.A, tc.B)))
61+
str := strWithout3a3b(tc.A, tc.B)
62+
ast.True(isCorrect(tc.A, tc.B, str), "A = %d, B = %d, %s", tc.A, tc.B, str)
5063
}
5164
}
5265

0 commit comments

Comments
 (0)