(AC) Elaborate python solution


  • 1
    R
    class Solution(object):
        def fizzBuzz(self, n):
            """
            :type n: int
            :rtype: 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
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.