-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
412.py
35 lines (31 loc) · 1.12 KB
/
412.py
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
27
28
29
30
31
32
33
34
35
__________________________________________________________________________________________________
sample 32 ms submission
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
res = []
for x in range(1,n+1):
if not x%3 and not x%5:
res.append('FizzBuzz')
elif not x%3:
res.append('Fizz')
elif not x%5:
res.append('Buzz')
else:
res.append(str(x))
return res
__________________________________________________________________________________________________
sample 13908 kb submission
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
ans = []
for i in range(1, n + 1):
if i % 15 == 0:
ans.append("FizzBuzz")
elif i % 5 == 0:
ans.append("Buzz")
elif i % 3 == 0:
ans.append("Fizz")
else:
ans.append(str(i))
return ans
__________________________________________________________________________________________________