FizzBuzz solution in python


  • 0
    D

    class Solution(object):
    def fizzBuzz(self, n):
    """
    :type n: int
    :rtype: List[str]
    """
    result = []
    for i in range(1,n+1):
    if i % 15 == 0:
    result.append('FizzBuzz')
    elif i % 5 == 0:
    result.append('Buzz')
    elif i % 3 == 0:
    result.append('Fizz')
    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.