2020년/코테

[코테 연습] Fizz Buzz Python

위지원 2020. 8. 28. 16:58

문제

 

https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3437/

 

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:]