# LeetCode - 412. Fizz Buzz

## 题目

Write a program that outputs the string representation of numbers from 1 to n.

But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.

Example:

n = 15,

Return:
[
"1",
"2",
"Fizz",
"4",
"Buzz",
"Fizz",
"7",
"8",
"Fizz",
"Buzz",
"11",
"Fizz",
"13",
"14",
"FizzBuzz"
]


## 常规思路

class Solution {
public List<String> fizzBuzz(int n) {
List<String> list = new ArrayList<>(n);
for (int i = 1; i <= n; i++) {
if (i % 15 == 0) {
} else if (i % 3 == 0) {
} else if (i % 5 == 0) {
} else {
}
}
return list;
}
}


Runtime: 1 ms
Memory Usage: 37.2 MB

## 特殊思路

public class Solution {
public List<String> fizzBuzz(int n) {
List<String> ret = new ArrayList<String>(n);
for(int i=1,fizz=0,buzz=0;i<=n ;i++){
fizz++;
buzz++;
if(fizz==3 && buzz==5){
fizz=0;
buzz=0;
}else if(fizz==3){
fizz=0;
}else if(buzz==5){
buzz=0;
}else{
}
}
return ret;
}
}


Runtime: 1 ms
Memory Usage: 37.3 MB

public class Solution {
public List<String> fizzBuzz(int n) {

List<String> result = new ArrayList<>();

if(n < 1) return result;

for(int i = 1, fizz = 3, buzz = 5; i <= n; i++) {

if(i == fizz && i == buzz) {
fizz += 3;
buzz += 5;
} else if(i == fizz) {
fizz += 3;
} else if(i == buzz) {
buzz += 5;
} else

}

return result;
}
}


Runtime: 1 ms
Memory Usage: 37.1 MB

## 补充：i+""和String.valueOf(i)

which is better between