LintCode: Fizz Buzz
C++
class Solution {
public:
/**
* param n: As description.
* return: A list of strings.
*/
vector<string> fizzBuzz(int n) {
vector<string> results;
for (int i = ; i <= n; i++) {
if (i % == ) {
results.push_back("fizz buzz");
} else if (i % == ) {
results.push_back("buzz");
} else if (i % == ) {
results.push_back("fizz");
} else {
results.push_back(to_string(i));
}
}
return results;
}
};
LintCode: Fizz Buzz的更多相关文章
- Lintcode 9.Fizz Buzz 问题
------------------------ AC代码: class Solution { /** * param n: As description. * return: A list of s ...
- LintCode (9)Fizz Buzz
下面是AC代码,C++风格: class Solution { public: vector<string> fizzBuzz(int N) { vector<string> ...
- [容易]Fizz Buzz 问题
题目来源:http://www.lintcode.com/zh-cn/problem/fizz-buzz/
- [LeetCode] Fizz Buzz 嘶嘶嗡嗡
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
- LeetCode 412. Fizz Buzz
Problem: Write a program that outputs the string representation of numbers from 1 to n. But for mult ...
- LeetCode Fizz Buzz
原题链接在这里:https://leetcode.com/problems/fizz-buzz/ 题目: Write a program that outputs the string represe ...
- Fizz Buzz
class Solution { public: /** * param n: As description. * return: A list of strings. */ vector<st ...
- [重构到模式-Chain of Responsibility Pattern]把Fizz Buzz招式重构到责任链模式
写一段程序从1打印到100,但是遇到3的倍数时打印Fizz,遇到5的倍数时打印Buzz,遇到即是3的倍数同时也是5的倍数时打印FizzBuzz.例如: 1 2 Fizz 4 Buzz Fizz 7 8 ...
- Swift完成fizz buzz test
看到一篇文章上说,很多貌似看过很多本编程书的童鞋连简单的fizz buzz测试都完不成. 不知道fizz buzz test为何物的,建议自行搜之. 测试要求是,编写满足以下条件的代码: Write ...
随机推荐
- 使用Brackets
Brackets功能还是很强大的. 官网:brackets.io常见问题解决:https://github.com/adobe/brackets/wiki/Troubleshooting快捷键:htt ...
- ArcGIS Desktop水文计算
根据DEM数据,可以做流域.流向.等级河流划分. 网络资源的方位位置: , Click here to visit. 一.一些概念 二.水文分析工具集概念
- ASIHTTPRequestErrorDomain Code=5
ASIHttpRequest解析带空格的URL时 出错!!!(已解决) 用的是post请求 URL 地址是: http://111.234.51.56/login_member.pl?time=201 ...
- i386、i586、i686、noarch、x86_64
xxxxxxxxx.rpm <== RPM的格式,已经经过编译且包装完成的rpm文件. xxxxxx.src.rpm <== SRPM的格式,包含未编译的源代码信息. 例如rp-p ...
- android4.0 中关于内外置sd卡的获取及读写权限问题
from://http://blog.chinaunix.net/uid-26727976-id-3146895.html 在2.x的版本中,在manifest中配置的权限android.permis ...
- mysql递归查询从子类ID查询所有父类
先来看数据表的结构如下: id name parent_id --------------------------- 1 Home 0 2 About ...
- ListView单条刷新的方法
我们一般会调用notifydatasetchange通知listView刷新界面.但会造成getView方法被多次调用(画面上能显示多少就会被调用多少次),如果是很明确的知道只更新了list中的某一个 ...
- The "Out of socket memory" error
The "Out of socket memory" error I recently did some work on some of our frontend machines ...
- 关于Base64编码的理解
版权声明:本文为[viclee]原创,如需转载请注明出处~ https://blog.csdn.net/goodlixueyong/article/details/52132250 之前在很多业务中都 ...
- [leetcode]Plus One @ Python
原题地址:https://oj.leetcode.com/problems/plus-one/ 题意: Given a non-negative number represented as an ar ...