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 2038bd7 commit ca0e9c2Copy full SHA for ca0e9c2
853-Car-Fleet.py
@@ -0,0 +1,10 @@
1
+class Solution:
2
+ def carFleet(self, target: int, position: List[int], speed: List[int]) -> int:
3
+ pair = [[p, s] for p, s in zip(position, speed)]
4
+
5
+ stack = []
6
+ for p, s in sorted(pair)[::-1]: # Reverse Sorted Order
7
+ stack.append((target - p) / s)
8
+ if len(stack) >= 2 and stack[-1] <= stack[-2]:
9
+ stack.pop()
10
+ return len(stack)
0 commit comments