We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 215ef8e commit e02f0bfCopy full SHA for e02f0bf
Python/single-threaded-cpu.py
@@ -0,0 +1,27 @@
1
+# Time: O(nlogn)
2
+# Space: O(n)
3
+
4
+import heapq
5
6
7
+class Solution(object):
8
+ def getOrder(self, tasks):
9
+ """
10
+ :type tasks: List[List[int]]
11
+ :rtype: List[int]
12
13
+ idx = range(len(tasks))
14
+ idx.sort(key=lambda x: tasks[x][0])
15
+ result, min_heap = [], []
16
+ i, time = 0, tasks[idx[0]][0]
17
+ while i < len(idx) or min_heap:
18
+ while i < len(idx) and tasks[idx[i]][0] <= time:
19
+ heapq.heappush(min_heap, (tasks[idx[i]][1], idx[i]))
20
+ i += 1
21
+ if not min_heap:
22
+ time = tasks[idx[i]][0]
23
+ continue
24
+ t, j = heapq.heappop(min_heap)
25
+ time += t
26
+ result.append(j)
27
+ return result
0 commit comments