Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 614 Bytes

File metadata and controls

29 lines (19 loc) · 614 Bytes

Question Link

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

Approach

Python Code

class Solution:
    def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
        trips_length = len(trips)
        
        if trips_length == 0:
            return True
        
        location = [0] * 1001
        
        for passengers, start, end in trips:
            
            for index in range(start, end):
                location[index] += passengers
                if location[index] > capacity:
                    return False
        
        return True

Code Explanation