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

Commit 5bc6c1c

Browse files
committed
984 accepted.
1 parent dc7d6a8 commit 5bc6c1c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ func strWithout3a3b(A int, B int) string {
66
var sb strings.Builder
77
sb.Grow(A + B)
88

9-
a, b := 'a', 'b'
9+
a, b := byte('a'), byte('b')
1010
if A < B {
1111
A, B = B, A
1212
a, b = b, a
1313
}
1414

15+
aab := []byte{a, a, b}
16+
17+
for A > B && B > 0 {
18+
sb.Write(aab)
19+
A -= 2
20+
B--
21+
}
22+
1523
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 && A-B < 2; i-- {
21-
sb.WriteRune(b)
24+
sb.WriteByte(a)
25+
A--
26+
if B > 0 {
27+
sb.WriteByte(b)
2228
B--
2329
}
2430
}

0 commit comments

Comments
 (0)