Merge pull request #152 from brenobaptista/refactored-412

Refactored solution 412 using string concatenation
This commit is contained in:
halfrost
2021-06-26 17:10:22 +08:00
committed by halfrost
19 changed files with 242 additions and 246 deletions

View File

@ -3,18 +3,16 @@ 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)
}
}