Car Pooling LeetCode solution in Python
1class Solution:2def carPooling(self, trips: List[List[int]], capacity: int) -> bool:3endheap = []4startheap = []56for i in range(len(trips)):7endheap.append((trips[i][2], trips[i][0], trips[i][1]))8startheap.append((trips[i][1], trips[i][0], trips[i][2]))9heapify(endheap)10heapify(startheap)11cur = 012while startheap:13start, num, end = heappop(startheap)14while start >= endheap[0][0]:15newend, newnum, newstart = heappop(endheap)16cur -= newnum17cur += num18print(cur)19if cur > capacity:20return False21return True