leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0412.cpp (357B)


      1 class Solution {
      2   public:
      3     vector<string> fizzBuzz(int n) {
      4         vector<string> res;
      5 
      6         for (int i = 1; i <= n; i++) {
      7             string s = "";
      8 
      9             if (i % 3 == 0) s += "Fizz";
     10 
     11             if (i % 5 == 0) s += "Buzz";
     12 
     13             if (s == "") s = to_string(i);
     14 
     15             res.push_back(s);
     16         }
     17         return res;
     18     }
     19 };