class Solution {
public:
/*
* @param n: An integer
* @return: A list of strings.
*/
vector<string> fizzBuzz(int n) {
// write your code here
vector<string> fizzBuzzVec;
string s;
for (int i = 1 ; i <= n ; i++) {
s = "";
stringstream ss;
if ((i % 3 == 0) && (i % 5 == 0)) {
fizzBuzzVec.push_back("fizz buzz");
} else if (i % 3 == 0) {
fizzBuzzVec.push_back("fizz");
} else if (i % 5 == 0) {
fizzBuzzVec.push_back("buzz");
} else {
ss<<i;
ss>>s;
fizzBuzzVec.push_back(s);
}
}
return fizzBuzzVec;
}
};
public:
/*
* @param n: An integer
* @return: A list of strings.
*/
vector<string> fizzBuzz(int n) {
// write your code here
vector<string> fizzBuzzVec;
string s;
for (int i = 1 ; i <= n ; i++) {
s = "";
stringstream ss;
if ((i % 3 == 0) && (i % 5 == 0)) {
fizzBuzzVec.push_back("fizz buzz");
} else if (i % 3 == 0) {
fizzBuzzVec.push_back("fizz");
} else if (i % 5 == 0) {
fizzBuzzVec.push_back("buzz");
} else {
ss<<i;
ss>>s;
fizzBuzzVec.push_back(s);
}
}
return fizzBuzzVec;
}
};