Skip to content

Commit 6497f3d

Browse files
committed
feat: 1109. Corporate Flight Bookings : 差分
1 parent f6c60ad commit 6497f3d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number[][]} bookings
3+
* @param {number} n
4+
* @return {number[]}
5+
*/
6+
const corpFlightBookings = function (bookings, n) {
7+
const diff = Array(n + 1).fill(0)
8+
for (const [f, l, s] of bookings) {
9+
diff[f] += s
10+
diff[l + 1] -= s
11+
}
12+
const ans = []
13+
for (let i = 1; i <= n; i++) {
14+
diff[i] += diff[i - 1]
15+
ans.push(diff[i])
16+
}
17+
return ans
18+
}

leetcode/残酷刷题/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- 2121. Intervals Between Identical Elements
4949
- 850. Rectangle Area II, 二维差分
5050
- 2132. Stamping the Grid
51+
- 1109. Corporate Flight Bookings: 差分
5152

5253
### 排序
5354

0 commit comments

Comments
 (0)