Refactored solution 412 using string concatenation

This commit is contained in:
Breno Baptista
2021-06-22 11:00:36 -03:00
parent 578c85e416
commit 8ae9b96b33

View File

@ -3,20 +3,23 @@ package leetcode
import "strconv"
func fizzBuzz(n int) []string {
if n < 0 {
return []string{}
}
solution := make([]string, n)
for i := 1; i <= n; i++ {
if i%3 == 0 && i%5 == 0 {
solution[i-1] = "FizzBuzz"
} else if i%3 == 0 {
solution[i-1] = "Fizz"
} else if i%5 == 0 {
solution[i-1] = "Buzz"
} else {
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
}