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 d2c7978 commit c401e5cCopy full SHA for c401e5c
1776-car-fleet-ii.js
@@ -1,3 +1,34 @@
1
+/**
2
+ * @param {number[][]} cars
3
+ * @return {number[]}
4
+ */
5
+const getCollisionTimes = function(cars) {
6
+ const n = cars.length;
7
+ const stack = [];
8
+ const res = Array(n)
9
+ for(let i = n - 1; i >= 0; i--) {
10
+ const [p, s] = cars[i]
11
+ res[i] = -1
12
+ while(stack.length) {
13
+ const j = stack[stack.length - 1]
14
+ const [p2, s2] = cars[j]
15
+ if(s2 >= s || res[j] > 0 && (p2 - p) / (s - s2) >= res[j]) stack.pop()
16
+ else break
17
+ }
18
+ if(stack.length) {
19
20
21
+ res[i] = (p2 - p) / (s - s2)
22
23
+ stack.push(i)
24
25
+
26
+ return res
27
+};
28
29
+// another
30
31
32
/**
33
* @param {number[][]} cars
34
* @return {number[]}
0 commit comments