FizzBuzz solution python using 1 for loop


  • 0
    S

    class Solution:
    def fizzBuzz(self, n):
    """
    :type n: int
    :rtype: List[str]
    """
    l =[]
    for i in range(1,n+1):
    if i%3 == 0:
    if i%5!=0:
    l.append('Fizz')
    else :
    l.append('FizzBuzz')
    elif i%5 == 0:
    l.append('Buzz')

            else:
                l.append(str(i))
        return l

Log in to reply
 

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