Skip to content

Commit c3ab53c

Browse files
committed
Runtime: 354 ms (Top 28.01%) | Memory: 13.9 MB (Top 55.93%)
1 parent e010122 commit c3ab53c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/algorithms/U/Ugly Number II/Ugly Number II.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Runtime: 354 ms (Top 28.01%) | Memory: 13.9 MB (Top 55.93%)
12
import heapq
23
class Solution:
34
def nthUglyNumber(self, n: int) -> int:
@@ -9,7 +10,7 @@ def nthUglyNumber(self, n: int) -> int:
910
last_ugly_number = 1
1011
count = 1
1112
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]:
1314
# pop from h1
1415
x = heapq.heappop(h1)
1516
ugly_number = 2 * x
@@ -21,7 +22,7 @@ def nthUglyNumber(self, n: int) -> int:
2122
heapq.heappush(h1, ugly_number)
2223
heapq.heappush(h2, ugly_number)
2324
heapq.heappush(h3, ugly_number)
24-
25+
2526
elif 3 * h2[0] <= 2 * h1[0] and 3 * h2[0] <= 5 * h3[0]:
2627
# pop from h2
2728
x = heapq.heappop(h2)
@@ -44,5 +45,5 @@ def nthUglyNumber(self, n: int) -> int:
4445
heapq.heappush(h1, ugly_number)
4546
heapq.heappush(h2, ugly_number)
4647
heapq.heappush(h3, ugly_number)
47-
48-
return last_ugly_number
48+
49+
return last_ugly_number

0 commit comments

Comments
 (0)