LeetCode412Fizz Buzz
写一个程序,输出从 1 到 n 数字的字符串表示。
1. 如果 n 是3的倍数,输出“Fizz”;
2. 如果 n 是5的倍数,输出“Buzz”;
3.如果 n 同时是3和5的倍数,输出 “FizzBuzz”。
示例:
n = 15, 返回: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz" ]
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> res;
for(int i = 1; i <= n; i++)
{
if(i % 3 == 0 && i % 5 == 0)
{
res.push_back("FizzBuzz");
}
else if(i % 3 == 0)
{
res.push_back("Fizz");
}
else if(i % 5 == 0)
{
res.push_back("Buzz");
}
else
{
res.push_back(to_string(i));
}
}
return res;
}
};
LeetCode412Fizz Buzz的更多相关文章
- [LeetCode] Fizz Buzz 嘶嘶嗡嗡
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
- 412. Fizz Buzz
https://leetcode.com/problems/fizz-buzz/ 没什么好说的,上一个小学生解法 class Solution(object): def fizzBuzz(self, ...
- Lintcode 9.Fizz Buzz 问题
------------------------ AC代码: class Solution { /** * param n: As description. * return: A list of s ...
- LeetCode 412. Fizz Buzz
Problem: Write a program that outputs the string representation of numbers from 1 to n. But for mult ...
- LeetCode之412. Fizz Buzz
-------------------------------------------- 虽然是从最简单的开始刷起,但木有想到LeetCode上也有这么水的题目啊... AC代码: public cl ...
- LeetCode Fizz Buzz
原题链接在这里:https://leetcode.com/problems/fizz-buzz/ 题目: Write a program that outputs the string represe ...
- Buzz words
给你一个字符串和字典,从头扫到位,如果到当前的字符的字符串存在于字典中,则显示 buzz. 例子: ILOVEPINEAPPLEJUICE 字典: [pine, apple, pineapple, j ...
- Fizz Buzz
class Solution { public: /** * param n: As description. * return: A list of strings. */ vector<st ...
- LintCode (9)Fizz Buzz
下面是AC代码,C++风格: class Solution { public: vector<string> fizzBuzz(int N) { vector<string> ...
随机推荐
- <小白学技术>将python脚本导出为exe可执行程序
1.简介(为啥需要导出为exe可执行程序) python写完的程序靠命令来执行,显得太专业,不符合python简单的特点(好吧,主要是太low) 代码给别人执行,别人没有你的python库也没法用(双 ...
- CVE-2016-0095提权漏洞分析
1 前言 瞻仰了k0shl和鹏哥 的漏洞分析,感慨万千,任重而道远. 2 系统环境和工具 windows 7 32旗舰版 windbg 3 poc 3.1poc复现 首先k0shl大佬给出的poc() ...
- python Selenium chromedriver 自动化超时报错:你需要使用多标签保护罩护体
在使用selenium + chrome 作自动化测试的时候,有可能会出现网页连接超时的情况 如果出现网页连接超时,将会导致 webdriver 也跟着无法响应,不能继续进行任何操作 即时是去打开新的 ...
- MySQL数据库CRUD命令用法
数据库CRUD操作即添加(Create).读取(Read).更新(Update)和删除(Delete). 1. 添加操作也称插入操作,使用Insert语句,Insert语句可以用于几种情况: 插入完整 ...
- js 类数组转化数组
一.常见类数组集合 (1).arguements function fn(){ var arr = [].slice.call(arguements,0); } (2).HTMLCollection ...
- Quartz:目录
ylbtech-Quartz:目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylbtec ...
- eclipse安装m2e
Installation You can install last M2Eclipse release by using the following update site from within E ...
- java基础温习 -- Thread
启动线程两种方式: 1. 实现Runnable接口: 2. 继承Thread类. 选用:能使用接口,就不用从Thread类继承. 使用继承的方法不够灵活,从这个类继承了就不能从其他类继承: 实现 ...
- sed awk 练习
#定位到某一行 添加内容 lower_case_flag=`cat /etc/my.cnf|grep "^lower_case_table_names"` if [ "X ...
- SpringMVC处理请求的大致流程是怎么样的
SpringMVC请求处理流程 Spring MVC请求处理架构图: 1.用户首先发送请求到前端控制器Dispatcher Servlet, 2.在doDispath这个方法中会为请求找到对 ...