Created
March 10, 2017 00:45
-
-
Save mindthink/8a7e0b1721a094fa17fbc6a8345c73f2 to your computer and use it in GitHub Desktop.
leetcode 412:Fizz Buzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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