Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Last active October 8, 2017 18:29
Show Gist options
  • Save cixuuz/aab5b4d43e0ea1ce0bf76bb668238868 to your computer and use it in GitHub Desktop.
Save cixuuz/aab5b4d43e0ea1ce0bf76bb668238868 to your computer and use it in GitHub Desktop.
[412. Fizz Buzz] #leetcode
class Solution(object):
// O(n) O(n)
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
res = []
for i in range(1, n+1):
three = i % 3 == 0
five = i % 5 == 0
if three and five:
res.append("FizzBuzz")
elif three:
res.append("Fizz")
elif five:
res.append("Buzz")
else:
res.append(str(i))
return res
class Solution(object):
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
return ["Fizz"*(i%3==0) + "Buzz"*(i%5==0) or str(i) for i in range(1, n+1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment