【LeetCode】412.Fizz Buzz_EASY(四)
来源:互联网 发布:hexo 知乎 编辑:程序博客网 时间:2024/06/06 03:34
412.Fizz Buzz
Description:
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”
]
这道题很简单,for循环加判断语句就能解决。
代码:
public class Solution { public List<String> fizzBuzz(int n) { List<String> list=new ArrayList<String>(); for(int i=1;i<=n;i++){ if(i%3==0&&i%5==0){ list.add("FizzBuzz"); }else if(i%3==0){ list.add("Fizz"); }else if(i%5==0){ list.add("Buzz"); }else{ list.add(String.valueOf(i)); } } return list; }}
完成。
0 0
- 【LeetCode】412.Fizz Buzz_EASY(四)
- 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
- 剑指offer——矩形覆盖
- BAT 技术团队博客
- linux操作学习08:系统服务的控制(systemctl 命令)
- Codeforces
- LeetCode 500. Keyboard Row
- 【LeetCode】412.Fizz Buzz_EASY(四)
- spark2.1.0版本 SparkSQL相关内容的测试和学习
- 算法提高 11-1实现strcmp函数
- hibernate通过HibernateCallback()调用底层session
- sscanf基本用法
- 用 config drive 配置网络
- support-v4、support-v7 的依赖关系及 Getting java.util.zip.ZipException: duplicate entry exception 的处理
- TensorFlow文本摘要生成
- MFC画图