Skip to content

Commit ca0e9c2

Browse files
authored
Create 853-Car-Fleet.py
1 parent 2038bd7 commit ca0e9c2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

853-Car-Fleet.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)