Write a program that outputs a string representation of the numbers 1 through N.

  1. If n is a multiple of 3, print “Fizz”;
  2. If n is a multiple of 5, output “Buzz”;

3. If n is a multiple of 3 and 5, FizzBuzz is displayed.

class Solution(object): def fizzBuzz(self, n): """ :type n: int :rtype: List[str] """ res = [] for i in range(1,n+1): print i if i%3 == 0 and i%5 ! =0: print "Fizz" res.append("Fizz") elif i%3 ! =0 and i%5 == 0: print "Buzz" res.append("Buzz") elif i%3 ==0 and i%5 == 0: print "FizzBuzz" res.append("FizzBuzz") else: print i res.append(str(i)) print '-----------' return resCopy the code