1109. Corporate Flight Bookings
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 64% Topics: Array, Prefix Sum
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def corpFlightBookings(self, bookings, n):
"""
:type bookings: List[List[int]]
:type n: int
:rtype: List[int]
"""
result = [0]*(n+1)
for i, j, k in bookings:
result[i-1] += k
result[j] -= k
for i in xrange(1, len(result)):
result[i] += result[i-1]
result.pop()
return result
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions