My simple and beat 95.16% python solution


  • 0
    S
    def fizzBuzz(self, n):
            out=[]
            for i in xrange(1,n+1):
                if i%3 and i%5:
                    out.append(str(i))
                else:
                    s=''
                    if i%3==0:
                        s='Fizz'
                    if i%5==0:
                        s=s+'Buzz'
                    out.append(s)
            
            return out
    

Log in to reply
 

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