-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path412-Fizz-Buzz.py
More file actions
26 lines (23 loc) · 796 Bytes
/
412-Fizz-Buzz.py
File metadata and controls
26 lines (23 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'''
Given an integer n, return a string array answer (1-indexed) where:
answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
answer[i] == "Fizz" if i is divisible by 3.
answer[i] == "Buzz" if i is divisible by 5.
answer[i] == i (as a string) if none of the above conditions are true.
'''
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
answer = []
for i in range(1, n + 1):
if((i % 3 == 0) and (i % 5 == 0)):
answer.append("FizzBuzz")
continue
elif(i % 3 == 0):
answer.append("Fizz")
continue
elif(i % 5 == 0):
answer.append("Buzz")
continue
else:
answer.append(str(i))
return answer