[LeetCode&Python] Problem 412. Fizz Buzz
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:
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
ans=[] for i in range(n):
if (i+1)%3==0:
if (i+1)%5==0:
ans.append('FizzBuzz')
else:
ans.append('Fizz')
elif (i+1)%5==0:
ans.append('Buzz')
else:
ans.append(str(i+1)) return ans
[LeetCode&Python] Problem 412. Fizz Buzz的更多相关文章
- 【leetcode】412. Fizz Buzz
problem 412. Fizz Buzz solution: class Solution { public: vector<string> fizzBuzz(int n) { vec ...
- Java实现 LeetCode 412 Fizz Buzz
412. Fizz Buzz 写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz" ...
- 【LeetCode】412. Fizz Buzz 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 方法一:遍历判断 方法二:字符串相加 方法三:字典 日期 [L ...
- [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
写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...
- 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
-------------------------------------------- 虽然是从最简单的开始刷起,但木有想到LeetCode上也有这么水的题目啊... AC代码: public cl ...
- LeetCode 412 Fizz Buzz 解题报告
题目要求 Write a program that outputs the string representation of numbers from 1 to n. But for multiple ...
随机推荐
- Codeforces 847E - Packmen
847E - Packmen 思路:二分时间. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long ...
- 更改Windows Update设置时,为何会提示“某些设置由你的系统管理员管理”?
亲测有效 及时进行更新是保证系统正常运行的一个有效措施.可为什么当我们进入“控制面板->Windows Update”手动修改 Windows Update 的设置时,系统却弹出提示“某些设置由 ...
- MyBatis中的@Mapper注解 @Mappe与@MapperScan关系
从mybatis3.4.0开始加入了@Mapper注解,目的就是为了不再写mapper映射文件 现在项目中的配置 public interface DemoMapper{ int deleteByPr ...
- Yii中的CComponent应用实例
首先我们先了解一下如何创建一个CComponent,手册讲述如下: CComponent 是所有组件类的基类. CComponent 实现了定义.使用属性和事件的协议. 属性是通过getter方法或/ ...
- (转)TeamViewer三种许可证的区别是什么?
xu言: 这几天在使用teamview对它的许可证做了一些了解,看到这个好像是官方的写的挺不错.留作收藏 PS:https://www.uret.in/ 顺便也发现了一个不错的网站 很多想要购买Te ...
- WPF全屏
https://blog.onedevjob.com/2010/10/19/fixing-full-screen-wpf-windows/ 让窗口重绘 Visibility = Visibility. ...
- codeforces 521a//DNA Alignment// Codeforces Round #295(Div. 1)
题意:如题定义的函数,取最大值的数量有多少? 结论只猜对了一半. 首先,如果只有一个元素结果肯定是1.否则.s串中元素数量分别记为a,t,c,g.设另一个串t中数量为a',t',c',g'.那么,固定 ...
- Android之 RecyclerView,CardView 详解和相对应的上拉刷新下拉加载
随着 Google 推出了全新的设计语言 Material Design,还迎来了新的 Android 支持库 v7,其中就包含了 Material Design 设计语言中关于 Card 卡片概念的 ...
- Confluence 6 获得 Active Directory 服务器证书
上面的步骤说明了如何在你的 Microsoft Active Directory服务器上安装 certification authority (CA).这一步,你需要为你的 Microsoft Act ...
- TCP-IP详解:Nagle算法
在使用一些协议通讯的时候,比如Telnet,会有一个字节字节的发送的情景,每次发送一个字节的有用数据,就会产生41个字节长的分组,20个字节的IP Header 和 20个字节的TCP Header, ...