Skip to content

Instantly share code, notes, and snippets.

@mindthink
Created March 10, 2017 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindthink/8a7e0b1721a094fa17fbc6a8345c73f2 to your computer and use it in GitHub Desktop.
Save mindthink/8a7e0b1721a094fa17fbc6a8345c73f2 to your computer and use it in GitHub Desktop.
leetcode 412:Fizz Buzz
class Solution(object):
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
l = []
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
l.append("FizzBuzz")
elif i % 3 == 0:
l.append("Fizz")
elif i % 5 == 0:
l.append("Buzz")
else:
l.append(str(i))
return l
if __name__ == '__main__':
sol = Solution()
n = 15
print(sol.fizzBuzz(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment