简单题
1 public class Solution { 2 public List<String> fizzBuzz(int n) { 3 List<String> ans = new ArrayList<String>(); 4 for (int i = 1; i <= n; i++) { 5 if (i % 3 == 0 && i % 5 == 0) { 6 ans.add("FizzBuzz"); 7 } 8 else if (i % 3 == 0) { 9 ans.add("Fizz"); 10 } 11 else if (i % 5 == 0) { 12 ans.add("Buzz"); 13 } 14 else ans.add(String.valueOf(i)); 15 } 16 return ans; 17 } 18 }