Fizz Buzz
2015-09-02 15:31
190 查看
class Solution { public: /** * param n: As description. * return: A list of strings. */ vector<string> fizzBuzz(int n) { vector<string> results; for (int i = 1; i <= n; i++) { if (i % 15 == 0) { results.push_back("fizz buzz"); } else if (i % 5 == 0) { results.push_back("buzz"); } else if (i % 3 == 0) { results.push_back("fizz"); } else { results.push_back(to_string(i)); } } return results; } };
相关文章推荐
- 轻松python之文件专题-关于zip文件的一些操作
- databus编译:Could not resolve all dependencies for configuration ':databus2-relay:databus2-event-producer-mock:compile
- python教程网址
- Linux shell学习随记
- 计算几何常用的函数/方法
- java按照map的value排序
- 如何在oracle中导入dmp数据库文件
- bitmap再出江湖:a.txt中有40亿个无符号整数, b.txt中有10000个无符号整数, 求交集。 可用内存:1G
- Java学习之排序
- linux文本编辑器
- HDU 1710 树的遍历
- priority_queue用法
- 总结_六天专题:栈和队列,树,并查集,KMP匹配算法
- HDU 1010 搜索+剪枝
- next_permutation用法 与 字典序
- STL入门资料
- 总结_搜索专题(四天)及练习赛总结
- 总结_ACM 之歌
- hdu 1846 (简单博弈题)
- hdu 1422 DP