We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 578c85e commit 8ae9b96Copy full SHA for 8ae9b96
leetcode/0412.Fizz-Buzz/412. Fizz Buzz.go
@@ -3,20 +3,23 @@ package leetcode
3
import "strconv"
4
5
func fizzBuzz(n int) []string {
6
- if n < 0 {
7
- return []string{}
8
- }
9
solution := make([]string, n)
+
10
for i := 1; i <= n; i++ {
11
- if i%3 == 0 && i%5 == 0 {
12
- solution[i-1] = "FizzBuzz"
13
- } else if i%3 == 0 {
14
- solution[i-1] = "Fizz"
15
- } else if i%5 == 0 {
16
- solution[i-1] = "Buzz"
17
- } else {
+ solution[i-1] = ""
+ if i%3 == 0 {
+ solution[i-1] += "Fizz"
+ }
+ if i%5 == 0 {
+ solution[i-1] += "Buzz"
18
19
+ if solution[i-1] == "" {
20
solution[i-1] = strconv.Itoa(i)
21
}
22
23
24
return solution
25
0 commit comments