본문 바로가기

IT/코딩테스트

[Leetcode] 412. Fizz Buzz

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