Skip to content

Commit 58ab0fe

Browse files
committed
feat: add solutions to lc problem: No.1109. Corporate Flight Bookings
1 parent d7baf73 commit 58ab0fe

File tree

4 files changed

+71
-13
lines changed

4 files changed

+71
-13
lines changed

solution/1100-1199/1109.Corporate Flight Bookings/README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,39 @@
6565
<!-- 这里可写当前语言的特殊实现逻辑 -->
6666

6767
```python
68-
68+
class Solution:
69+
def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
70+
delta = [0] * n
71+
for first, last, seats in bookings:
72+
delta[first - 1] += seats
73+
if last < n:
74+
delta[last] -= seats
75+
for i in range(n - 1):
76+
delta[i + 1] += delta[i]
77+
return delta
6978
```
7079

7180
### **Java**
7281

7382
<!-- 这里可写当前语言的特殊实现逻辑 -->
7483

7584
```java
76-
85+
class Solution {
86+
public int[] corpFlightBookings(int[][] bookings, int n) {
87+
int[] delta = new int[n];
88+
for (int[] booking : bookings) {
89+
int first = booking[0], last = booking[1], seats = booking[2];
90+
delta[first - 1] += seats;
91+
if (last < n) {
92+
delta[last] -= seats;
93+
}
94+
}
95+
for (int i = 0; i < n - 1; ++i) {
96+
delta[i + 1] += delta[i];
97+
}
98+
return delta;
99+
}
100+
}
77101
```
78102

79103
### **JavaScript**

solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,37 @@ Hence, answer = [10,25]
5858
### **Python3**
5959

6060
```python
61-
61+
class Solution:
62+
def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
63+
delta = [0] * n
64+
for first, last, seats in bookings:
65+
delta[first - 1] += seats
66+
if last < n:
67+
delta[last] -= seats
68+
for i in range(n - 1):
69+
delta[i + 1] += delta[i]
70+
return delta
6271
```
6372

6473
### **Java**
6574

6675
```java
67-
76+
class Solution {
77+
public int[] corpFlightBookings(int[][] bookings, int n) {
78+
int[] delta = new int[n];
79+
for (int[] booking : bookings) {
80+
int first = booking[0], last = booking[1], seats = booking[2];
81+
delta[first - 1] += seats;
82+
if (last < n) {
83+
delta[last] -= seats;
84+
}
85+
}
86+
for (int i = 0; i < n - 1; ++i) {
87+
delta[i + 1] += delta[i];
88+
}
89+
return delta;
90+
}
91+
}
6892
```
6993

7094
### **JavaScript**
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
class Solution {
22
public int[] corpFlightBookings(int[][] bookings, int n) {
3-
int[] res = new int[n];
3+
int[] delta = new int[n];
44
for (int[] booking : bookings) {
5-
int b = booking[0] - 1, e = booking[1], k = booking[2];
6-
res[b] += k;
7-
if (e < n) {
8-
res[e] -= k;
5+
int first = booking[0], last = booking[1], seats = booking[2];
6+
delta[first - 1] += seats;
7+
if (last < n) {
8+
delta[last] -= seats;
99
}
1010
}
11-
for (int i = 1; i < n; ++i) {
12-
res[i] += res[i - 1];
11+
for (int i = 0; i < n - 1; ++i) {
12+
delta[i + 1] += delta[i];
1313
}
14-
return res;
14+
return delta;
1515
}
16-
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
3+
delta = [0] * n
4+
for first, last, seats in bookings:
5+
delta[first - 1] += seats
6+
if last < n:
7+
delta[last] -= seats
8+
for i in range(n - 1):
9+
delta[i + 1] += delta[i]
10+
return delta

0 commit comments

Comments
 (0)