Skip to content

Instantly share code, notes, and snippets.

@qiaoxu123
Created March 22, 2019 08:16
Show Gist options
  • Save qiaoxu123/57a42cf0e8c0cba3c692cde08575fa96 to your computer and use it in GitHub Desktop.
Save qiaoxu123/57a42cf0e8c0cba3c692cde08575fa96 to your computer and use it in GitHub Desktop.
> 简单粗暴的for循环
//Runtime: 12 ms, faster than 57.21%
//Memory Usage: 10.5 MB, less than 48.01%
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> array;
for(int i = 1;i <= n;++i){
if(i % 3 == 0 && i % 5 != 0)
array.push_back("Fizz");
else if(i % 5 == 0 && i % 3 != 0)
array.push_back("Buzz");
else if(i % 5 == 0 && i % 3 == 0)
array.push_back("FizzBuzz");
else
array.push_back(to_string(i));
}
return array;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment