We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent faec736 commit c3e4c76Copy full SHA for c3e4c76
1834-single-threaded-cpu.js
@@ -209,3 +209,33 @@ class PriorityQueue {
209
}
210
211
212
+
213
+// another
214
+/**
215
+ * @param {number[][]} tasks
216
+ * @return {number[]}
217
+ */
218
+const getOrder = function(tasks) {
219
+ const n = tasks.length
220
+ const pq = new PriorityQueue((a, b) => a[0] === b[0] ? a[1] < b[1] : a[0] < b[0])
221
+ tasks.forEach((e, i) => e.push(i))
222
+ tasks.sort((a, b) => a[0] - b[0])
223
+ let idx = 0, time = 0
224
+ const res = []
225
226
+ while(idx < n || !pq.isEmpty()) {
227
+ while(idx < n && tasks[idx][0] <= time) {
228
+ pq.push([tasks[idx][1], task[idx][2]])
229
+ idx++
230
+ }
231
+ if(!pq.isEmpty()) {
232
+ const tmp = pq.pop()
233
+ time += tmp[0]
234
+ res.push(tmp[1])
235
+ } else if(idx < n) {
236
+ time = tasks[idx][0]
237
238
239
+ return res
240
241
+};
0 commit comments