Skip to content

Latest commit

 

History

History
27 lines (24 loc) · 575 Bytes

fizz-buzz.MD

File metadata and controls

27 lines (24 loc) · 575 Bytes

Fizz Buzz (LeetCode)

https://leetcode.com/problems/fizz-buzz/

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