Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 67e2118

Browse files
committed
109 added
1 parent 3ad849f commit 67e2118

File tree

4 files changed

+206
-33
lines changed

4 files changed

+206
-33
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# [1109. Corporate Flight Bookings](https://leetcode.com/problems/corporate-flight-bookings/)
2+
3+
There are n flights, and they are labeled from 1 to n.
4+
5+
We have a list of flight bookings. The i-th booking bookings[i] = [i, j, k] means that we booked k seats from flights labeled i to j inclusive.
6+
7+
Return an array answer of length n, representing the number of seats booked on each flight in order of their label.
8+
9+
Example 1:
10+
11+
```text
12+
Input: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
13+
Output: [10,55,45,25,25]
14+
```
15+
16+
Constraints:
17+
18+
- `1 <= bookings.length <= 20000`
19+
- `1 <= bookings[i][0] <= bookings[i][1] <= n <= 20000`
20+
- `1 <= bookings[i][2] <= 10000`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem1109
2+
3+
func corpFlightBookings(bookings [][]int, n int) []int {
4+
5+
return nil
6+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package problem1109
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
bookings [][]int
12+
n int
13+
ans []int
14+
}{
15+
16+
{
17+
[][]int{{1, 2, 10}, {2, 3, 20}, {2, 5, 25}},
18+
5,
19+
[]int{10, 55, 45, 25, 25},
20+
},
21+
22+
// 可以有多个 testcase
23+
}
24+
25+
func Test_corpFlightBookings(t *testing.T) {
26+
ast := assert.New(t)
27+
28+
for _, tc := range tcs {
29+
ast.Equal(tc.ans, corpFlightBookings(tc.bookings, tc.n), "输入:%v", tc)
30+
}
31+
}
32+
33+
func Benchmark_corpFlightBookings(b *testing.B) {
34+
for i := 0; i < b.N; i++ {
35+
for _, tc := range tcs {
36+
corpFlightBookings(tc.bookings, tc.n)
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)