class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> ans;
for(int i = 1; i<=n; i++){
string res="";
if(i % 3 == 0)
res +="Fizz";
if(i % 5 == 0)
res += "Buzz";
if(res.length() == 0){
int m = i;
while(m > 0){
res = char(m%10+'0')+res;
m /= 10;
}
}
ans.push_back(res);
}
return ans;
}
};
leetcode 412. Fizz Buzz
最新推荐文章于 2024-07-22 16:27:42 发布