File tree 2 files changed +50
-0
lines changed
infrastructure/src/resources
2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
3
+
4
+ class Solution :
5
+ """
6
+ Time: O(n)
7
+ Memory: O(1)
8
+ """
9
+
10
+ FIZZ = 3
11
+ BUZZ = 5
12
+
13
+ def fizzBuzz (self , n : int ) -> List [str ]:
14
+ nums = [str (num ) for num in range (1 , n + 1 )]
15
+
16
+ for fizz in range (self .FIZZ - 1 , n , self .FIZZ ):
17
+ nums [fizz ] = 'Fizz'
18
+
19
+ for buzz in range (self .BUZZ - 1 , n , self .BUZZ ):
20
+ nums [buzz ] = 'Buzz'
21
+
22
+ for fizzbuzz in range (self .FIZZ * self .BUZZ - 1 , n , self .FIZZ * self .BUZZ ):
23
+ nums [fizzbuzz ] = 'FizzBuzz'
24
+
25
+ return nums
26
+
27
+
28
+ class Solution :
29
+ """
30
+ Time: O(n)
31
+ Memory: O(1)
32
+ """
33
+
34
+ FIZZ = 3
35
+ BUZZ = 5
36
+
37
+ def fizzBuzz (self , n : int ) -> List [str ]:
38
+ nums = []
39
+
40
+ for num in range (1 , n + 1 ):
41
+ if not num % (self .FIZZ * self .BUZZ ):
42
+ nums .append ('FizzBuzz' )
43
+ elif not num % self .FIZZ :
44
+ nums .append ('Fizz' )
45
+ elif not num % self .BUZZ :
46
+ nums .append ('Buzz' )
47
+ else :
48
+ nums .append (str (num ))
49
+
50
+ return nums
You can’t perform that action at this time.
0 commit comments