Problem:
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" ]
-Summary-
1. if number i is divisible by both, we append 'FizzBuzz' to the list.
2. if number i is divisible by only 3, we append 'Fizz' to the list.
3. if number i is divisible by only 5, we append 'Buzz' to the list.
4. if number i is not divisible by 3 and 5, then we append string of the number to the list.
모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]
'LeetCode > Top Interview Q. - Easy' 카테고리의 다른 글
LeetCode. Count Primes [Math] (0) | 2020.06.15 |
---|---|
LeetCode. Count Primes [Math] (0) | 2020.06.14 |
LeetCode 5. Valid Parentheses [Strings, Stack] (0) | 2020.06.12 |
LeetCode. House Robber [Dynamic Programming] (0) | 2020.06.12 |
LeetCode. Maximum Subarray [Dynamic Programming] (0) | 2020.06.11 |
댓글