Fizz Buzz LeetCode solution in C++

1
class Solution {
2
public:
3
vector<string> fizzBuzz(int n) {
4
vector<string> ans;
5
string hehe;
6
for (int i = 1; i <= n; i++) {
7
if (i % 3 == 0 and i % 5 == 0)
8
hehe += "FizzBuzz";
9
else if (i % 3 == 0)
10
hehe += "Fizz";
11
else if (i % 5 == 0)
12
hehe += "Buzz";
13
else
14
hehe = to_string(i);
15
ans.push_back(hehe);
16
hehe = "";
17
}
18
return ans;
19
}
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0