Title Description
Writing a program, it outputs a number from 1 to n strings.
1. 如果 n 是3的倍数,输出“Fizz”;
2. 如果 n 是5的倍数,输出“Buzz”;
3. 如果 n 同时是3和5的倍数,输出 “FizzBuzz”。
Example:
n = 15,
返回:
[
"1",
"2",
"Fizz",
"4",
"Buzz",
"Fizz",
"7",
"8",
"Fizz",
"Buzz",
"11",
"Fizz",
"13",
"14",
"FizzBuzz"
]
Topic analysis
Sieve element method similar thinking, all elements initialized to an empty string, then the elements of a multiple of 3 plus "Fizz", plus a multiple element 5 "Buzz", through the entire array and the array of hollow string assigned to the order.
Source
1 |
大专栏 Leetcode 412.FizzBuzz"line">class { |