LC.1109. Corporate Flight Bookings

LC.1109. Corporate Flight Bookings_第1张图片

class Solution(object):
    def corpFlightBookings(self, bookings, n):
        """
        for (start, end, n) in booking
        相当于公交车在start的地方上来了n个人,在end+1的地方下去了n个人,这样每一站车上的人数就是每个航班被预定的座位数
        """
        bus = [0]*(n+1)
        for start, end , book in bookings:
            bus[start] += book
            if end + 1 <= n:
                bus[end+1] -= book
        for i in range(1, len(bus)):
            bus[i] += bus[i-1]
        return bus[1:]

你可能感兴趣的:(LeetCode)