Fizz Buzz
来源:互联网 发布:压缩相片软件下载 编辑:程序博客网 时间:2024/05/17 09:01
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 “FizzBuz
Example:
n = 15,Return:[ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]class Solution(object):
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
s=[]
if(n==0):
return s
i=1
while i<=n:
if(i%3==0 and i%5==0):
s.append("FizzBuzz")
elif(i%3==0):
s.append("Fizz")
elif(i%5==0):
s.append("Buzz")
else:
s.append(str(i))
i=i+1
return s
0 0
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz programming
- [刷题]Fizz Buzz
- 题目:Fizz Buzz
- LintCode: Fizz Buzz
- Fizz Buzz 问题
- JavaWeb前端知识-CSS初级
- python学习代码每日汇总
- 天梯赛总结
- ViewPager添加图片横向自动轮播
- 第一次参加天梯赛的感受
- Fizz Buzz
- poj 3349 Snowflake Snow Snowflakes(hash)
- border-radius不仅仅可以用来画圆哦
- js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度实现代码
- java语言复制数组的四种方法
- C语言算法—(生成子集的升级)生成数据的全部组合(含重复数字)(类似建立树的回溯法)
- 使用lock对象显示的锁定资源
- 对Java的URL类支持的协议进行扩展的方法
- java 字符串连接