Python | Leetcode Python题解之第412题Fizz Buzz
题目:
题解:
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
ans = []
for i in range(1, n + 1):
s = ""
if i % 3 == 0:
s += "Fizz"
if i % 5 == 0:
s += "Buzz"
if s == "":
s = str(i)
ans.append(s)
return ans