码迷,mamicode.com
首页 > 其他好文 > 详细

LintCode: Fizz Buzz

时间:2015-12-01 12:35:16      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

C++

 1 class Solution {
 2 public:
 3     /**
 4      * param n: As description.
 5      * return: A list of strings.
 6      */
 7     vector<string> fizzBuzz(int n) {
 8         vector<string> results;
 9         for (int i = 1; i <= n; i++) {
10             if (i % 15 == 0) {
11                 results.push_back("fizz buzz");
12             } else if (i % 5 == 0) {
13                 results.push_back("buzz");
14             } else if (i % 3 == 0) {
15                 results.push_back("fizz");
16             } else {
17                 results.push_back(to_string(i));
18             }
19         }
20         return results;
21     }
22 };

 

LintCode: Fizz Buzz

标签:

原文地址:http://www.cnblogs.com/CheeseZH/p/5009668.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!