C++ 6ms 5 lines


  • 0
    vector<string> fizzBuzz(int n) {
            vector<string> ans;
            
            for (int i = 1; i <= n; i++) {
                ans.push_back(i % 3 && i % 5 ? to_string(i) : string(i % 3 ? "" : "Fizz") + string(i % 5 ? "" : "Buzz"));
            }
            
            return ans;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.