--------------------------------------------

虽然是从最简单的开始刷起,但木有想到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的更多相关文章

  1. 【leetcode】412. Fizz Buzz

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

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

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

  3. 力扣(LeetCode)412. Fizz Buzz

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

  4. Java实现 LeetCode 412 Fizz Buzz

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

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

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

  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&Python] Problem 412. Fizz Buzz

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

  8. LeetCode: 412 Fizz Buzz(easy)

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

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

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

随机推荐

  1. hihoCoder 后缀自动机三·重复旋律6

    后缀自动机三·重复旋律6 时间限制:15000ms 单点时限:3000ms 内存限制:512MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为一段数构成的数列. 现在小Hi ...

  2. 关于line-height

    line-height不允许负值,给定值之后会根据font-size计算行高,line-height指定的行高是行高最小值,设置height可以增大行高 line-height的计算:以px为例,li ...

  3. NGUI 滑动特效之中间放大滚动

    效果图如下: 其实很简单,在NGUI原有的滑动组件的基础上处理一下比例系数就好,每个块的位置是固定的,移动的是Panel. 所以呢用Panel的位置与块的位置做差在比几个块不就成了比例系数了么..自然 ...

  4. Nodejs - 如何用 eventproxy 模块控制并发

    本文目标 本文的目标是获取 ZOJ 1001-1010 每道题 best solution 的作者 id,取得数据后一次性输出在控制台. 前文 如何用 Nodejs 分析一个简单页面 我们讲了如何用 ...

  5. insert into output使用

    declare @t table (logId int,customerId int,amount int) insert into log( customerId,amount) output in ...

  6. shell判断条件整理

    1.字符串判断 str1 = str2 当两个字符串串有相同内容.长度时为真 str1 != str2 当字符串str1和str2不等时为真 -n str1 当字符串的长度大于0时为真(串非空) -z ...

  7. C#使用 DirectX SDK 9做视频播放器 并在视频画线添加文字 VMR9

    视频图像处理系列 索引 VS2013下测试通过. 在百度中搜索关键字“DirectX SDk”,或者进入微软官网https://www.microsoft.com/en-us/download/det ...

  8. Google Maps API V3 之 图层

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  9. UIScrollView无法滚动的解决办法

    如果UIScrollView无法滚动,可能是以下原因: 没有设置contentSize scrollEnabled = NO 没有接收到触摸事件:userInteractionEnabled = NO ...

  10. Windows平台下Qt中glut库的使用

    用Qt中的QGLWidget窗体类中是不包括glut工具库的,难怪在myGLWidget(在我的程序中是QGLWidget的派生类)中绘制实心球体是说“glutSolidSphere”: 找不到标识符 ...