2020년/코테
[코테 연습] Fizz Buzz Python
위지원
2020. 8. 28. 16:58
문제
Explore - LeetCode
LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.
leetcode.com
푸는데 걸린 시간: 3분
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
res = ["" for _ in range(n+1)]
for i in range(n+1):
if i % 5 == 0 and i%3 == 0:
res[i] = "FizzBuzz"
elif i % 5 == 0:
res[i] = "Buzz"
elif i % 3 == 0:
res[i] = "Fizz"
else:
res[i] = str(i)
return res[1:]