Java实现 LeetCode 412 Fizz Buzz
412. Fizz Buzz
写一个程序,输出从 1 到 n 数字的字符串表示。
如果 n 是3的倍数,输出“Fizz”;
如果 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 List<String> fizzBuzz(int n) {
List<String> ret=new ArrayList<>();
for(int i=1;i<=n;i++){
if(i%15==0) ret.add("FizzBuzz");
else if(i%3==0) ret.add("Fizz");
else if(i%5==0) ret.add("Buzz");
else ret.add(Integer.toString(i));
}
return ret;
}
}
Java实现 LeetCode 412 Fizz Buzz的更多相关文章
- [LeetCode] 412. 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: 412 Fizz Buzz(easy)
题目: Write a program that outputs the string representation of numbers from 1 to n. But for multiples ...
- LeetCode 412 Fizz Buzz 解题报告
题目要求 Write a program that outputs the string representation of numbers from 1 to n. But for multiple ...
- LeetCode - 412. Fizz Buzz - ( C++ ) - 解题报告 - to_string
1.题目大意 Write a program that outputs the string representation of numbers from 1 to n. But for multip ...
- 【leetcode】412. Fizz Buzz
problem 412. Fizz Buzz solution: class Solution { public: vector<string> fizzBuzz(int n) { vec ...
- 力扣(LeetCode)412. Fizz Buzz
写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...
- 【LeetCode】412. Fizz Buzz 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 方法一:遍历判断 方法二:字符串相加 方法三:字典 日期 [L ...
- [LeetCode&Python] Problem 412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
随机推荐
- 【matlab 基础篇 02】基础知识一键扫盲,看完即可无障碍编程(超详细+图文并茂)
博主快速入门matlab,系统地整理一遍,如何你和我一样是一个新手,那么此文很适合你: 本人能力有限,文中难免有错误和纰漏之处,请大佬们不吝赐教 创作不易,如果本文帮到了您: 请帮忙点个赞
- OpenCV Error: Unspecified Error(The Function is not implemented)
Ubuntu 或者 Debian 系统显示窗口的时候遇到了这个问题 error: (-2:Unspecified error) The function is not implemented. Reb ...
- input在IOS中的聚焦问题
关于input输入框在iPhone手机中的聚焦问题,开发中是会经常遇到的,在一般的浏览器中,我们一般是通过 document.getElementById('opop').focus(); 来获取焦点 ...
- [hdu5199]统计数据的水题
题意:统计一个数出现了多少次,统计后删去它所有的出现.思路:乱搞..自己没事写的hash,不过赶脚效率有点低. #pragma comment(linker, "/STACK:1024000 ...
- 使用Python创建一个系统监控程序--李渣渣(lizaza.cn)
最近在做个人网站,但是由于服务器资源不足,偶尔会出现系统崩溃的现象,所以想写一个程序来实时监控系统状态.当系统资源占用过高时发送邮件提醒. psutil(进程和系统实用程序)是一个跨平台的库,用于检索 ...
- python--遇到SyntaxError: Non-UTF-8 code starting with '\xb8' in file
在运行python中因为添加了中文注释,遇到SyntaxError: Non-UTF-8 code starting with '\xb8' in file 经过百度,说是Python的默认编码格式是 ...
- Web_php_unserialize-攻防世界XCTF
0x00 简介 记录一下,重点是记录一下那篇正则文章. 0x01 题目代码 <?php class Demo { private $file = 'index.php'; public func ...
- sql:exists 与 not exists
$sql = "select a.Vchcode,a.vdate,a.btypeid,a.vcomment,a.total,a.vnumber,b.bfullname,b.artotal,b ...
- Navicat15 for Mysql激活教程
1.下载Navicat Premium Navicat15链接:http://www.navicat.com.cn/download/navicat-premium,选择相应版本,这里选择window ...
- Atcoder Beginner Contest 167
赛场实况: 训练反思: A题签到不说了,B题第一眼没看清楚数据范围,写了一堆然后仔细一看1e12果断不能暴力..立马换了一个写法,连交2发wa(细节啊细节!!),C题看了半天英语没看懂说了什么,拿翻译 ...