C++ | Leetcode C++题解之第412题Fizz Buzz
题目:
题解:
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> answer;
for (int i = 1; i <= n; i++) {
string curr;
if (i % 3 == 0) {
curr += "Fizz";
}
if (i % 5 == 0) {
curr += "Buzz";
}
if (curr.size() == 0) {
curr += to_string(i);
}
answer.emplace_back(curr);
}
return answer;
}
};