412. Fizz Buzz - leetcode
来源:互联网 发布:安米app源码 编辑:程序博客网 时间:2024/05/22 03:47
- 412. Fizz Buzz - leetcode
Write a program that outputs the string representation of numbersfrom 1 to n.
But for multiples of three it should output “Fizz” instead of thenumber and for the multiples of five output “Buzz”. For numbers which aremultiples of both three and five output “FizzBuzz”.
n = 15,
Return:
[
"1",
"2",
"Fizz",
"4",
"Buzz",
"Fizz",
"7",
"8",
"Fizz",
"Buzz",
"11",
"Fizz",
"13",
"14",
"FizzBuzz"
]
这道题一定是太简单了,几分钟就AC了。。
用了python的list, for in
class Solution(object): def fizzBuzz(self, n): """ :type n: int :rtype: List[str] """ d=[] for i in range(1,n+1): if i%3==0 and i%5==0: d.append('FizzBuzz') elif i%3==0: d.append('Fizz') elif i%5==0: d.append('Buzz') else: d.append(str(i)) return d
阅读全文
0 0
- 412. Fizz Buzz - leetcode
- 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 412. Fizz Buzz
- 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--412. Fizz Buzz
- 412. Fizz Buzz [LeetCode]
- [leetcode]--412. Fizz Buzz
- Leetcode-412. Fizz Buzz
- 音频器件
- Marching squares (triangle)
- 摘要-图解算法
- html基础学习之用户交互,控件使用
- C语言实现员工管理系统
- 412. Fizz Buzz - leetcode
- 《模式分类》读书笔记(绪论)
- 暑假测试 Day 5
- canvas绘图折线图表
- 日志分析查看——grep,sed,sort,awk运用
- Creating Threads
- 洛谷P1478 陶陶摘苹果(升级版,dp)
- error: field * has incomplete type
- JDBC学习笔记(一)