mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 00:56:33 +08:00
21 lines
329 B
Go
21 lines
329 B
Go
package leetcode
|
|
|
|
import "strconv"
|
|
|
|
func fizzBuzz(n int) []string {
|
|
solution := make([]string, n)
|
|
for i := 1; i <= n; i++ {
|
|
solution[i-1] = ""
|
|
if i%3 == 0 {
|
|
solution[i-1] += "Fizz"
|
|
}
|
|
if i%5 == 0 {
|
|
solution[i-1] += "Buzz"
|
|
}
|
|
if solution[i-1] == "" {
|
|
solution[i-1] = strconv.Itoa(i)
|
|
}
|
|
}
|
|
return solution
|
|
}
|