注意Integer2String的写法是
String.valueOf(int)
或者
Integer.toString(int)
70.40 %
class Solution {
public List<String> fizzBuzz(int n) {
List<String> list = new ArrayList<>();
for (int i = 1; i <= n; i++) {
if (i % 15 == 0) list.add("FizzBuzz");
else if (i % 3 == 0) list.add("Fizz");
else if (i % 5 == 0) list.add("Buzz");
else list.add(String.valueOf(i));
}
return list;
}
}
No comments:
Post a Comment