1094. Car Pooling
Medium
Input: trips = [[2,1,5],[3,3,7]], capacity = 4
Output: falseInput: trips = [[2,1,5],[3,3,7]], capacity = 5
Output: trueLast updated
Input: trips = [[2,1,5],[3,3,7]], capacity = 4
Output: falseInput: trips = [[2,1,5],[3,3,7]], capacity = 5
Output: trueLast updated
class Solution:
def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
l = []
for trip in trips:
l.append((trip[1], trip[0]))
l.append((trip[2], -trip[0]))
l.sort()
passenger_in_car = 0
for point, num in l:
passenger_in_car += num
if passenger_in_car > capacity:
return False
return True