Участник:Plague rat/Car Pooling

Материал из DISCOPAL
Перейти к: навигация, поиск

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

class Solution:
    def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
        stopPoints = []
        for trip in trips:
            stopPoints.append(tuple([trip[1], trip[0]]))
            stopPoints.append(tuple([trip[2], -trip[0]]))
        stopPoints = sorted(stopPoints)
        currentPeopleCount = 0
        for point in stopPoints:
            currentPeopleCount += point[1]
            if currentPeopleCount > capacity:
                return False
        return True