Skip to content

Commit 1daaee1

Browse files
authored
chore: add new lc problems (doocs#1326)
1 parent 3cc43f5 commit 1daaee1

File tree

14 files changed

+810
-0
lines changed

14 files changed

+810
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# [2793. 航班机票状态](https://leetcode.cn/problems/status-of-flight-tickets)
2+
3+
[English Version](/solution/2700-2799/2793.Status%20of%20Flight%20Tickets/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>表:&nbsp;<code><font face="monospace">Flights</font></code></p>
10+
11+
<pre>
12+
+-------------+------+
13+
| 列名 | 类型 |
14+
+-------------+------+
15+
| flight_id | int |
16+
| capacity | int |
17+
+-------------+------+
18+
flight_id 是该表的主键列。
19+
每行包含航班 id 和座位容量。
20+
</pre>
21+
22+
<p>表:<code>Passengers</code></p>
23+
24+
<pre>
25+
+--------------+----------+
26+
| 列名 | 类型 |
27+
+--------------+----------+
28+
| passenger_id | int |
29+
| flight_id | int |
30+
| booking_time | datetime |
31+
+--------------+----------+
32+
passenger_id 是该表的主键。
33+
booking_time 包含不同的值。
34+
每行包含乘客 id、预订时间和所预订的航班 id。
35+
</pre>
36+
37+
<p>乘客提前预订航班机票。如果乘客预订了一张航班机票,并且航班上还有空座位,则乘客的机票将 <strong>得到确认</strong> 。然而,如果航班已经满员,乘客将被列入 <strong>等候名单</strong> 。</p>
38+
39+
<p>编写一个 SQL 查询来确定每个乘客航班机票的当前状态。</p>
40+
41+
<p>按 <code>passenger_id</code> <strong>升序排序&nbsp;</strong>返回结果表。</p>
42+
43+
<p>查询结果的格式如下所示。</p>
44+
45+
<p>&nbsp;</p>
46+
47+
<p><strong class="example">示例 1:</strong></p>
48+
49+
<pre>
50+
<b>输入:</b>
51+
Flights 表:
52+
+-----------+----------+
53+
| flight_id | capacity |
54+
+-----------+----------+
55+
| 1 | 2 |
56+
| 2 | 2 |
57+
| 3 | 1 |
58+
+-----------+----------+
59+
Passengers 表:
60+
+--------------+-----------+---------------------+
61+
| passenger_id | flight_id | booking_time |
62+
+--------------+-----------+---------------------+
63+
| 101 | 1 | 2023-07-10 16:30:00 |
64+
| 102 | 1 | 2023-07-10 17:45:00 |
65+
| 103 | 1 | 2023-07-10 12:00:00 |
66+
| 104 | 2 | 2023-07-05 13:23:00 |
67+
| 105 | 2 | 2023-07-05 09:00:00 |
68+
| 106 | 3 | 2023-07-08 11:10:00 |
69+
| 107 | 3 | 2023-07-08 09:10:00 |
70+
+--------------+-----------+---------------------+
71+
<b>输出:</b>
72+
+--------------+-----------+
73+
| passenger_id | Status |
74+
+--------------+-----------+
75+
| 101 | Confirmed |
76+
| 102 | Waitlist |
77+
| 103 | Confirmed |
78+
| 104 | Confirmed |
79+
| 105 | Confirmed |
80+
| 106 | Waitlist |
81+
| 107 | Confirmed |
82+
+--------------+-----------+
83+
<b>解释:</b>
84+
- 航班 1 的容量为 2 位乘客。乘客 101 和乘客 103 是最先预订机票的,已经确认他们的预订。然而,乘客 102 是第三位预订该航班的乘客,这意味着没有更多的可用座位。乘客 102 现在被列入等候名单。
85+
- 航班 2 的容量为 2 位乘客,已经有两位乘客预订了机票,乘客 104 和乘客 105。由于预订机票的乘客数与可用座位数相符,这两个预订都得到了确认。
86+
- 航班 3 的容量为 1 位乘客,乘客 107 先预订并获得了唯一的可用座位,确认了他们的预订。预订时间在乘客 107 之后的乘客 106 被列入等候名单。</pre>
87+
88+
## 解法
89+
90+
<!-- 这里可写通用的实现逻辑 -->
91+
92+
<!-- tabs:start -->
93+
94+
### **SQL**
95+
96+
<!-- 这里可写当前语言的特殊实现逻辑 -->
97+
98+
```sql
99+
100+
```
101+
102+
<!-- tabs:end -->
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# [2793. Status of Flight Tickets](https://leetcode.com/problems/status-of-flight-tickets)
2+
3+
[中文文档](/solution/2700-2799/2793.Status%20of%20Flight%20Tickets/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code><font face="monospace">Flights</font></code></p>
8+
9+
<pre>
10+
+-------------+------+
11+
| Column Name | Type |
12+
+-------------+------+
13+
| flight_id | int |
14+
| capacity | int |
15+
+-------------+------+
16+
<code>flight_id</code> is the primary key column for this table.
17+
Each row of this table contains flight id and capacity.
18+
</pre>
19+
20+
<p>Table: <code>Passengers</code></p>
21+
22+
<pre>
23+
+--------------+----------+
24+
| Column Name | Type |
25+
+--------------+----------+
26+
| passenger_id | int |
27+
| flight_id | int |
28+
| booking_time | datetime |
29+
+--------------+----------+
30+
passenger_id is the primary key column for this table.
31+
booking_time column contains distinct values.
32+
Each row of this table contains passenger id, booking time, and their flight id.
33+
</pre>
34+
35+
<p>Passengers book tickets for flights in advance. If a passenger books a ticket for a flight and there are still empty seats available on the flight, the passenger&#39;s ticket will be <strong>confirmed</strong>. However, the passenger will be on a <strong>waitlist</strong> if the flight is already at full capacity.</p>
36+
37+
<p>Write an SQL query to determine the current status of flight tickets for each passenger.</p>
38+
39+
<p>Return <em>the result table ordered by</em> <code>passenger_id</code> <em>in <strong>ascending order</strong>.</em></p>
40+
41+
<p>The query result format is in the following example.</p>
42+
43+
<p>&nbsp;</p>
44+
<p><strong class="example">Example 1:</strong></p>
45+
46+
<pre>
47+
<strong>Input:</strong>
48+
Flights table:
49+
+-----------+----------+
50+
| flight_id | capacity |
51+
+-----------+----------+
52+
| 1 | 2 |
53+
| 2 | 2 |
54+
| 3 | 1 |
55+
+-----------+----------+
56+
Passengers table:
57+
+--------------+-----------+---------------------+
58+
| passenger_id | flight_id | booking_time |
59+
+--------------+-----------+---------------------+
60+
| 101 | 1 | 2023-07-10 16:30:00 |
61+
| 102 | 1 | 2023-07-10 17:45:00 |
62+
| 103 | 1 | 2023-07-10 12:00:00 |
63+
| 104 | 2 | 2023-07-05 13:23:00 |
64+
| 105 | 2 | 2023-07-05 09:00:00 |
65+
| 106 | 3 | 2023-07-08 11:10:00 |
66+
| 107 | 3 | 2023-07-08 09:10:00 |
67+
+--------------+-----------+---------------------+
68+
<strong>Output:</strong>
69+
+--------------+-----------+
70+
| passenger_id | Status |
71+
+--------------+-----------+
72+
| 101 | Confirmed |
73+
| 102 | Waitlist |
74+
| 103 | Confirmed |
75+
| 104 | Confirmed |
76+
| 105 | Confirmed |
77+
| 106 | Waitlist |
78+
| 107 | Confirmed |
79+
+--------------+-----------+
80+
<strong>Explanation:</strong>
81+
- Flight 1 has a capacity of 2 passengers. Passenger 101 and Passenger 103 were the first to book tickets, securing the available seats. Therefore, their bookings are confirmed. However, Passenger 102 was the third person to book a ticket for this flight, which means there are no more available seats. Passenger 102 is now placed on the waitlist,
82+
- Flight 2 has a capacity of 2 passengers, Flight 2 has exactly two passengers who booked tickets, Passenger 104 and Passenger 105. Since the number of passengers who booked tickets matches the available seats, both bookings are confirmed.
83+
- Flight 3 has a capacity of 1 passenger. Passenger 107 booked earlier and secured the only available seat, confirming their booking. Passenger 106, who booked after Passenger 107, is on the waitlist.
84+
</pre>
85+
86+
## Solutions
87+
88+
<!-- tabs:start -->
89+
90+
### **SQL**
91+
92+
```sql
93+
94+
```
95+
96+
<!-- tabs:end -->
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# [2794. 从两个数组中创建对象](https://leetcode.cn/problems/create-object-from-two-arrays)
2+
3+
[English Version](/solution/2700-2799/2794.Create%20Object%20from%20Two%20Arrays/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给定两个数组 <code>keysArr </code>和 <code>valuesArr</code>,返回一个新的对象 <code>obj</code>。<code>obj</code> 中的每个键值对都来自 <code>keysArr[i]</code> 和 <code>valuesArr[i]</code>。</p>
10+
11+
<p>- 如果前面的索引中存在重复的键,则应该跳过该键值对。换句话说,只有第一次出现的键会被添加到对象中。</p>
12+
13+
<p>- 如果键不是字符串,则应通过调用 <code>String()</code> 方法将其转换为字符串。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong class="example">示例 1:</strong></p>
18+
19+
<pre>
20+
<b>输入:</b>arr1 = ["a", "b", "c"], arr2 = [1, 2, 3]
21+
<b>输出:</b>{"a": 1, "b": 2, "c": 3}
22+
<b>解释:</b>键 "a"、"b" 和 "c" 分别与值 1、2 和 3 配对。
23+
</pre>
24+
25+
<p><strong class="example">示例 2:</strong></p>
26+
27+
<pre>
28+
<b>输入:</b>arr1 = ["1", 1, false], arr2 = [4, 5, 6]
29+
<b>输出:</b>{"1": 4, "false": 6}
30+
<b>解释:</b>首先,将 arr1 中的所有元素转换为字符串。我们可以看到有两个 "1" 的出现。使用第一次出现 "1" 的关联值:4。
31+
</pre>
32+
33+
<p><strong class="example">示例 3:</strong></p>
34+
35+
<pre>
36+
<b>输入:</b>arr1 = [], arr2 = []
37+
<b>输出:</b>{}
38+
<b>解释:</b>没有键,因此返回一个空对象。
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
43+
<p><strong>提示:</strong></p>
44+
45+
<ul>
46+
<li><code>arr1 和 arr2 都是有效的 JSON 数组</code></li>
47+
<li><code>2 &lt;= JSON.stringify(arr1).length &lt;= 5 * 10<sup>5</sup></code></li>
48+
<li><code>2 &lt;= JSON.stringify(arr2).length &lt;= 5 * 10<sup>5</sup></code></li>
49+
<li><code>arr1.length === arr2.length</code></li>
50+
</ul>
51+
52+
## 解法
53+
54+
<!-- 这里可写通用的实现逻辑 -->
55+
56+
<!-- tabs:start -->
57+
58+
### **TypeScript**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```ts
63+
64+
```
65+
66+
<!-- tabs:end -->
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# [2794. Create Object from Two Arrays](https://leetcode.com/problems/create-object-from-two-arrays)
2+
3+
[中文文档](/solution/2700-2799/2794.Create%20Object%20from%20Two%20Arrays/README.md)
4+
5+
## Description
6+
7+
<p>Given two arrays <code>keysArr</code> and <code>valuesArr</code>, return a new object <code>obj</code>. Each key-value pair in&nbsp;<code>obj</code>&nbsp;should come from&nbsp;<code>keysArr[i]</code>&nbsp;and&nbsp;<code>valuesArr[i]</code>.</p>
8+
9+
<p>- If a duplicate key exists at a previous index, that key-value should be excluded. In other words, only the first key should be added to the object.</p>
10+
11+
<p>- If the key is not a string, it should be converted into a string by calling `String()` on it.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> arr1 = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;], arr2 = [1, 2, 3]
18+
<strong>Output:</strong> {&quot;a&quot;: 1, &quot;b&quot;: 2, &quot;c&quot;: 3}
19+
<strong>Explanation:</strong> The keys &quot;a&quot;, &quot;b&quot;, and &quot;c&quot; are paired with the values 1, 2, and 3 respectively.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> arr1 = [&quot;1&quot;, 1, false], arr2 = [4, 5, 6]
26+
<strong>Output:</strong> {&quot;1&quot;: 4, &quot;false&quot;: 6}
27+
<strong>Explanation:</strong> First, all the elements in arr1 are converted into strings. We can see there are two occurrences of &quot;1&quot;. The value associated with the first occurrence of &quot;1&quot; is used: 4.
28+
</pre>
29+
30+
<p><strong class="example">Example 3:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> arr1 = [], arr2 = []
34+
<strong>Output:</strong> {}
35+
<strong>Explanation:</strong> There are no keys so an empty object is returned.
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>arr1 and arr2 are valid JSON arrays</code></li>
43+
<li><code>2 &lt;= JSON.stringify(arr1).length &lt;= 5 * 10<sup>5</sup></code></li>
44+
<li><code>2 &lt;= JSON.stringify(arr2).length &lt;= 5 * 10<sup>5</sup></code></li>
45+
<li><code>arr1.length === arr2.length</code></li>
46+
</ul>
47+
48+
## Solutions
49+
50+
<!-- tabs:start -->
51+
52+
### **TypeScript**
53+
54+
```ts
55+
56+
```
57+
58+
<!-- tabs:end -->

0 commit comments

Comments
 (0)