Car Pooling LeetCode solution in Python

1
class Solution:
2
def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
3
endheap = []
4
startheap = []
5

6
for i in range(len(trips)):
7
endheap.append((trips[i][2], trips[i][0], trips[i][1]))
8
startheap.append((trips[i][1], trips[i][0], trips[i][2]))
9
heapify(endheap)
10
heapify(startheap)
11
cur = 0
12
while startheap:
13
start, num, end = heappop(startheap)
14
while start >= endheap[0][0]:
15
newend, newnum, newstart = heappop(endheap)
16
cur -= newnum
17
cur += num
18
print(cur)
19
if cur > capacity:
20
return False
21
return True

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0