2
public int[] corpFlightBookings(int[][] bookings, int n) {3
// nums all equals to zero4
int[] nums = new int[n];6
Difference df = new Difference(nums);8
for (int[] booking : bookings) {9
// pay attention to the index10
int i = booking[0] - 1;11
int j = booking[1] - 1;13
// increase nums[i..j] by val14
df.increment(i, j, val);16
// return the final array24
public Difference(int[] nums) {25
assert nums.length > 0;26
diff = new int[nums.length];27
// construct the diffs29
for (int i = 1; i < nums.length; i++) {30
diff[i] = nums[i] - nums[i - 1];34
// increase nums[i..j] by val35
public void increment(int i, int j, int val) {37
if (j + 1 < diff.length) {42
public int[] result() {43
int[] res = new int[diff.length];44
// contract the diff array based on the result46
for (int i = 1; i < diff.length; i++) {47
res[i] = res[i - 1] + diff[i];