Skip to content

Commit 6fdc494

Browse files
committed
fix: solution of 412
1 parent 195f042 commit 6fdc494

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
func fizzBuzz(n int) (ans []string) {
2-
for i := 1; i <= n; i++ {
3-
s := &strings.Builder{}
4-
if i%3 == 0 {
5-
s.WriteString("Fizz")
2+
ans := make([]string, 0, n)
3+
for i := 1; i < n+1; i++ {
4+
switch {
5+
case i%15 == 0:
6+
ans = append(ans, "FizzBuzz")
7+
case i%3 == 0:
8+
ans = append(ans, "Fizz")
9+
case i%5 == 0:
10+
ans = append(ans, "Buzz")
11+
default:
12+
ans = append(ans, strconv.Itoa(i))
613
}
7-
if i%5 == 0 {
8-
s.WriteString("Buzz")
9-
}
10-
if s.Len() == 0 {
11-
s.WriteString(strconv.Itoa(i))
12-
}
13-
ans = append(ans, s.String())
1414
}
15-
return
15+
return ans
1616
}

0 commit comments

Comments
 (0)