Skip to content

Commit 92601f0

Browse files
committed
412 Fizz Buzz.py
1 parent 6a8638f commit 92601f0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

412 Fizz Buzz.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution(object):
2+
def fizzBuzz(self, n):
3+
"""
4+
:type n: int
5+
:rtype: List[str]
6+
"""
7+
next_fizz = 1
8+
next_buzz = 1
9+
next_fizzbuzz = 1
10+
result = []
11+
for i in range(1,n+1):
12+
if i == next_fizzbuzz * 15:
13+
result.append("FizzBuzz")
14+
next_fizzbuzz += 1
15+
next_fizz += 1
16+
next_buzz += 1
17+
elif i == next_fizz * 3:
18+
result.append("Fizz")
19+
next_fizz += 1
20+
elif i == next_buzz * 5:
21+
result.append("Buzz")
22+
next_buzz += 1
23+
else:
24+
result.append(str(i))
25+
26+
return result
27+

0 commit comments

Comments
 (0)