728x90
https://leetcode.com/problems/fizz-buzz/
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
result = []
for i in range(1, n+1):
if ((i % 3 == 0) and (i % 5 == 0)):
result.append('FizzBuzz')
elif (i % 3 == 0):
result.append('Fizz')
elif (i % 5 == 0):
result.append('Buzz')
else:
result.append(str(i))
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 383. Ransom Note (0) | 2023.08.11 |
---|---|
[Leetcode] 511. Game Play Analysis I (0) | 2023.08.10 |
[Leetcode] 1342. Number of Steps to Reduce a Number to Zero (0) | 2023.08.09 |
[Leetcode] 1672. Richest Customer Wealth (0) | 2023.08.08 |
[Leetcode] 1480. Running Sum of 1d Array (0) | 2023.08.07 |