class Solution:
"""
@param n: An integer
@return: A list of strings.
"""
def fizzBuzz(self, n):
# write your code here
m="fizz"
l="buzz"
h="fizz buzz"
y=[]
for i in range(1,n+1):
if i % 3 == 0 and i % 5 != 0:
y.append(m)
if i % 5 == 0 and i % 3 != 0:
y.append(l)
if i % 3 == 0 and i % 5 == 0:
y.append(h)
if i % 3 != 0 and i % 5 != 0:
y.append(str(i))
return y
lintcode 9.fizz buzz问题
最新推荐文章于 2024-07-27 12:20:46 发布