LeetCode Fizz Buzz
来源:互联网 发布:sqlserver集群 编辑:程序博客网 时间:2024/06/02 05:55
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”
]
Subscribe to see which companies asked this question.
class Solution(object): def fizzBuzz(self, n): """ :type n: int :rtype: list[str] """ res = [] for i in xrange(1,n+1): if i%15 ==0: res.append("FizzBuzz") elif i%3 == 0: res.append("Fizz") elif i%5 ==0: res.append("Buzz") else: res.append(i) return resif __name__ == '__main__': print Solution().fizzBuzz(15)
0 0
- LeetCode 412. Fizz Buzz
- LeetCode 412 Fizz Buzz
- [LeetCode]--412. Fizz Buzz
- LeetCode-412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- LeetCode #412: Fizz Buzz
- LeetCode 刷题: Fizz Buzz
- 【leetcode】412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- leetcode 412. Fizz Buzz
- Fizz Buzz ----LeetCode
- leetcode 412. Fizz Buzz
- Leetcode 412.Fizz Buzz
- leetcode-412. Fizz Buzz
- leetcode之Fizz Buzz
- LeetCode 412. Fizz Buzz
- Leetcode 412 Fizz Buzz
- 【LeetCode】 412. Fizz Buzz
- (转)Android
- 第一个cmake,实例学习,项目管理
- myeclipse中的快捷键
- jQuery中scrollTop()方法解析
- CentOS 7 安装 Elasticsearch5.2.2
- LeetCode Fizz Buzz
- 百度云python客户端bypy的上传命令(upload)
- Linux下的三个时间
- 欢迎使用CSDN-markdown编辑器
- 为什么局域网要用mac地址而不直接使用IP地址
- 数字组合-动态规划(01背包)-openjudge
- 跳过来吧!
- HashMap的原理分析(1)put方法的实现
- 使用SublimeText作为Markdown编辑器