Skip to content

Instantly share code, notes, and snippets.

@mindthink mindthink/412.py
Created Mar 10, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.