We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 20765da commit 253e1a4Copy full SHA for 253e1a4
1184-car-pooling/car-pooling.py
@@ -0,0 +1,21 @@
1
+import heapq
2
+
3
+class Solution:
4
+ def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
5
+ trips = sorted(trips, key=lambda x: x[1])
6
7
+ in_car = []
8
9
+ for num, start, end in trips:
10
+ capacity -= num
11
12
+ heapq.heappush(in_car, (end, num))
13
14
+ while in_car and in_car[0][0] <= start:
15
+ capacity += in_car[0][1]
16
+ heapq.heappop(in_car)
17
18
+ if capacity < 0:
19
+ return False
20
21
+ return True
0 commit comments