leetcode 412. Fizz Buzz

    vector<string> fizzBuzz(int n) {
        vector<string> ret;
        
        for (int i = 1; i <= n; i++) {
            bool three = i % 3 == 0;
            bool five = i % 5 == 0;
            if (three && five)
                ret.push_back("FizzBuzz");
            else if (three)
                ret.push_back("Fizz");
            else if (five)
                ret.push_back("Buzz");
            else
                ret.push_back(to_string(i));
        }
        return move(ret);
    }

 

posted on 2018-02-18 14:08  willaty  阅读(125)  评论(0编辑  收藏  举报

导航