Write a program that outputs the string representation of numbers from 1 to n.

But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.

Example:

n = 15,

Return:
[
"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 = ; i <= n; ++i) {
if (i % == ) res.push_back("FizzBuzz");
else if (i % == ) res.push_back("Fizz");
else if (i % == ) res.push_back("Buzz");
else res.push_back(to_string(i));
}
return res;
}
};

LeetCode All in One 题目讲解汇总(持续更新中...)

[LeetCode] Fizz Buzz 嘶嘶嗡嗡的更多相关文章

  1. LeetCode——Fizz Buzz

    LeetCode--Fizz Buzz Question Write a program that outputs the string representation of numbers from ...

  2. [LeetCode] 412. Fizz Buzz 嘶嘶嗡嗡

    Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...

  3. LeetCode Fizz Buzz

    原题链接在这里:https://leetcode.com/problems/fizz-buzz/ 题目: Write a program that outputs the string represe ...

  4. LeetCode算法题-Fizz Buzz(Java实现)

    这是悦乐书的第221次更新,第233篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第88题(顺位题号是412). 编写一个程序,输出从1到n的数字的字符串表示.但对于三的 ...

  5. 【LeetCode】412. Fizz Buzz 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 方法一:遍历判断 方法二:字符串相加 方法三:字典 日期 [L ...

  6. LeetCode 412. Fizz Buzz

    Problem: Write a program that outputs the string representation of numbers from 1 to n. But for mult ...

  7. 【leetcode】412. Fizz Buzz

    problem 412. Fizz Buzz solution: class Solution { public: vector<string> fizzBuzz(int n) { vec ...

  8. Leetcode 414.Fizz Buzz By Python

    写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...

  9. 力扣(LeetCode)412. Fizz Buzz

    写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...

随机推荐

  1. 搭建了个人的github.io博客

    地址:http://www.shutu.tech 说明: 基于github + hexo简易搭建的个人博客,用于收藏经典博文及技术文章,也会用于个人的技术成长记录.我是看到这篇文章搭建的:http:/ ...

  2. ASP.NET Core 中文文档 第三章 原理(8)日志

    原文:Logging 作者:Steve Smith 翻译:刘怡(AlexLEWIS) 校对:何镇汐.许登洋(Seay) ASP.NET Core 内建支持日志,也允许开发人员轻松切换为他们想用的其他日 ...

  3. 修复 Visual Studio Error “No exports were found that match the constraint”

    清空Visual Studio 文件缓存目录 Just delete or rename this folder: %AppData%\..\Local\Microsoft\VisualStudio\ ...

  4. sql 补齐字段位数

    select top 100 lmdte, right(replicate('0',6)+ltrim(lmtme),6) from smtpdsum where lmdte <> 0

  5. Chart: Who pays the most in Seattle for software engineers

    http://www.geekwire.com/2012/chart-pays-seattle-software-engineers/ Chart: Who pays the most in Seat ...

  6. macOS 升级到了10.12.1

    除了明面上的一些更新,但我感觉最重要的是触摸板的行为特征又还原了.

  7. c语言实现输入一组数自动从大到小排列

    #include <stdio.h>main(){    int x;    printf("请输入要排序数字个数:");    scanf("%d" ...

  8. j2ee log4j集中式日志解决方案logpool-v0.2

    下一个小版本会进行清理. war包下载地址 http://pan.baidu.com/s/1nvGmORn

  9. BranchCache在sharepoint2013使用

    BranchCache 是 Windows 7.Windows 8.Windows Server 2008 R2 和 Windows Server 2012 操作系统的一项功能,此功能可在本地分支机构 ...

  10. SDK接入(1)之Android Facebook SDK接入

    SDK接入(1)之Android Facebook SDK接入 由于游戏已上线,且处于维护阶段,所以有空写写各种SDK接入过程和遇到的问题,也当作一种工作总结.SDK接入主流分为这么几类,登录.支付. ...