Posted on

Description

Submission

class Solution {
public:
    vector<string> fizzBuzz(int n) {
        vector<string> rets;
        for(int i = 1; i <= n; ++i)
            if(i % 3 == 0 && i % 5 == 0) {
                rets.push_back("FizzBuzz");
            } else if(i % 3 == 0) {
                rets.push_back("Fizz");
            } else if(i % 5 == 0) {
                rets.push_back("Buzz");
            } else {
                rets.push_back(to_string(i));
            }
        return rets;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *