File tree 1 file changed +5
-4
lines changed
scripts/algorithms/U/Ugly Number II
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change
1
+ # Runtime: 354 ms (Top 28.01%) | Memory: 13.9 MB (Top 55.93%)
1
2
import heapq
2
3
class Solution :
3
4
def nthUglyNumber (self , n : int ) -> int :
@@ -9,7 +10,7 @@ def nthUglyNumber(self, n: int) -> int:
9
10
last_ugly_number = 1
10
11
count = 1
11
12
while count < n :
12
- if 2 * h1 [0 ] <= 3 * h2 [0 ] and 2 * h1 [0 ] <= 5 * h3 [0 ]:
13
+ if 2 * h1 [0 ] <= 3 * h2 [0 ] and 2 * h1 [0 ] <= 5 * h3 [0 ]:
13
14
# pop from h1
14
15
x = heapq .heappop (h1 )
15
16
ugly_number = 2 * x
@@ -21,7 +22,7 @@ def nthUglyNumber(self, n: int) -> int:
21
22
heapq .heappush (h1 , ugly_number )
22
23
heapq .heappush (h2 , ugly_number )
23
24
heapq .heappush (h3 , ugly_number )
24
-
25
+
25
26
elif 3 * h2 [0 ] <= 2 * h1 [0 ] and 3 * h2 [0 ] <= 5 * h3 [0 ]:
26
27
# pop from h2
27
28
x = heapq .heappop (h2 )
@@ -44,5 +45,5 @@ def nthUglyNumber(self, n: int) -> int:
44
45
heapq .heappush (h1 , ugly_number )
45
46
heapq .heappush (h2 , ugly_number )
46
47
heapq .heappush (h3 , ugly_number )
47
-
48
- return last_ugly_number
48
+
49
+ return last_ugly_number
You can’t perform that action at this time.
0 commit comments