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"
]
没想太多,简单粗暴解决,AC了。
public List<String> fizzBuzz(int n) {
List<String> list =

该博客介绍了一种简单的Python程序,用于根据Fizz Buzz规则输出从1到n的数字字符串表示。当数字是3的倍数时,输出“Fizz”,是5的倍数时输出“Buzz”,同时是3和5的倍数时输出“FizzBuzz”。博主通过直接判断和条件输出实现了这个算法并获得了LeetCode的正确答案。
订阅专栏 解锁全文
696

被折叠的 条评论
为什么被折叠?



