Leetcode412. Fizz Buzz
来源:互联网 发布:网络暴力的案例 编辑:程序博客网 时间:2024/05/17 21:54
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”.
public List<String> fizzBuzz(int n) { String a = "Fizz"; String b = "Buzz"; List<String> res = new ArrayList<>(); for (int i = 1; i <= n; i++) { StringBuilder stringBuilder = new StringBuilder(); if (i%3==0){ stringBuilder.append(a); } if(i%5==0){ stringBuilder.append(b); } else if(i%3!=0&&i%5!=0){ stringBuilder.append(i); } res.add(stringBuilder.toString()); } return res; }
阅读全文
0 0
- leetcode412: Fizz Buzz
- Leetcode412. Fizz Buzz
- [LeetCode412] Fizz Buzz
- Leetcode412. Fizz Buzz
- leetcode412. Fizz Buzz
- python--leetcode412. Fizz Buzz
- 20.leetCode412: Fizz Buzz
- Leetcode412. Fizz Buzz爱美之心人皆有之
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- Fizz Buzz
- 深入解析Glide源码
- Discovery:解决错误2
- NYOJ:31-5个数求最值
- Python 学习日知录(三)- 创建多个Logger
- GIT 自动补全命令,分支名 以及 高亮显示当前分支
- Leetcode412. Fizz Buzz
- struts国际化
- 前端学习笔记--AJAX的使用(二)
- java高并发
- NYOJ:32-组合数
- Java创建对象
- Android Service的基本用法(1)
- NYOJ:33-蛇形填数
- leetcode