Leetcode 1184 Solution

This article provides solution to leetcode question 1184 (car-pooling)

https://leetcode.com/problems/car-pooling

Solution

class Solution: def carPooling(self, trips: List[List[int]], capacity: int) -> bool: events = []
for num, src, dst in trips: events.append((src, num)) events.append((dst, -num))
events.sort()
curr = 0
for loc, cnt in events: curr += cnt
if curr > capacity: return False
return True