# 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; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up