Created
March 22, 2019 08:16
-
-
Save qiaoxu123/57a42cf0e8c0cba3c692cde08575fa96 to your computer and use it in GitHub Desktop.
> 简单粗暴的for循环
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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