LeetCode之412. Fizz Buzz

--------------------------------------------
虽然是从最简单的开始刷起,但木有想到LeetCode上也有这么水的题目啊。。。
AC代码:
public class Solution {
public List<String> fizzBuzz(int n) {
List<String> res=new ArrayList<>();
for(int i=1;i<=n;i++){
if(i/3*3==i && i/5*5==i) res.add("FizzBuzz");
else if(i/3*3==i) res.add("Fizz");
else if(i/5*5==i) res.add("Buzz");
else res.add(Integer.toString(i));
}
return res;
}
}
题目来源: https://leetcode.com/problems/fizz-buzz/
LeetCode之412. Fizz Buzz的更多相关文章
- 【leetcode】412. Fizz Buzz
problem 412. Fizz Buzz solution: class Solution { public: vector<string> fizzBuzz(int n) { vec ...
- 【LeetCode】412. Fizz Buzz 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 方法一:遍历判断 方法二:字符串相加 方法三:字典 日期 [L ...
- 力扣(LeetCode)412. Fizz Buzz
写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...
- Java实现 LeetCode 412 Fizz Buzz
412. Fizz Buzz 写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"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&Python] Problem 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(easy)
题目: Write a program that outputs the string representation of numbers from 1 to n. But for multiples ...
- LeetCode算法题-Fizz Buzz(Java实现)
这是悦乐书的第221次更新,第233篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第88题(顺位题号是412). 编写一个程序,输出从1到n的数字的字符串表示.但对于三的 ...
随机推荐
- 最为简易的yii 教程(一)
了解目录的框架结构 framework主要有 base 框架核心组件 caching 缓存组件 db 数据库组件 gii ...
- bzoj4462: [Jsoi2013]编程作业
KMP还是有点用处的嘛qwq 对于小写字母,修改其为前一个这个小写字母和它的距离 然后跑KMP就行了 跑得飞快 #include <iostream> #include <cstdi ...
- hackerrank Similar Pair
传送门 Problem Statement You are given a tree where each node is labeled from 1 to n. How many similar ...
- MySQL基本命令
1.修改root用户登录密码: [root@17track bin]# /usr/local/mysql/bin/mysqladmin -u root password 'MyPassword' my ...
- JS实现网页批量下载文件,支持PC/手机
//把下载链接放入集合里 var downloadData = new Array{"http://www.empli.com/data1.apk","http://ww ...
- CSS书写顺序
CSS书写顺序 1.位置属性(position, top, right, z-index, display, float等)2.大小(width, height, margin, padding)3. ...
- PHP WAMP 文件上传 及 简单的上传预览
...... 使用特殊的表单类型file, 主(上传)页面: <form action="chuli.php" method="post" enctype ...
- Jquery动态添加的元素绑定事件的3种方法
假设我们点击li标签,弹出他的文本,如果是动态添加的li,点击是没有效果的,压根弹不出来文本. 下面博主分享一下为动态添加的元素绑定事件的三种方法,网上一般都是两种,我在这里多增加了一种. 事件案例: ...
- Python Day1
一.安装python windows 1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装到C盘下 3.配置环境变量 右键计算机属性---高级系统设置 ...
- 浅谈Android下的Bitmap之大Bitmap加载
引言 我们常常提到的“Android程序优化”,通常指的是性能和内存的优化,即:更快的响应速度,更低的内存占用.Android程序的性能和内存问题,大部分都和图片紧密相关,而图片的加载在很多情况下很用 ...