---
# System prepended metadata

title: 1109. Corporate Flight Bookings
tags: [Leetcode, 差分法, Medium]

---

# 1109. Corporate Flight Bookings
###### tags: `Leetcode` `Medium` `差分法`
Link: https://leetcode.com/problems/corporate-flight-bookings/
## 思路 $O(N)$ $O(1)$
差分法
## Code
```java=
class Solution {
    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] line = new int[n];
        for(int[] booking: bookings){
            line[booking[0]-1] += booking[2];
            if(booking[1]!=n) line[booking[1]] -= booking[2];
        }
        for(int i=1; i<line.length; i++){
            line[i] += line[i-1];
        }
        return line;
    }
}
```