1184. Car Pooling
My accepted Python solution to LeetCode problem 1184, Car Pooling, running in 1ms.
- Difficulty: Medium
- Python
- Runtime 1ms
- Memory 17.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 1ms, memory 17.9MB, accepted 2026-01-02.
class Solution:
def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
# Difference array approach
changes = [0] * 1001
for num_passengers, from_loc, to_loc in trips:
changes[from_loc] += num_passengers
changes[to_loc] -= num_passengers
current = 0
for change in changes:
current += change
if current > capacity:
return False
return True