Skip to content

Commit d49d8c0

Browse files
committed
feat: add new lc problems
1 parent 8784aea commit d49d8c0

File tree

18 files changed

+1129
-22
lines changed

18 files changed

+1129
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# [2152. Minimum Number of Lines to Cover Points](https://leetcode-cn.com/problems/minimum-number-of-lines-to-cover-points)
2+
3+
[English Version](/solution/2100-2199/2152.Minimum%20Number%20of%20Lines%20to%20Cover%20Points/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are given an array <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on an <strong>X-Y </strong>plane.</p>
10+
11+
<p><strong>Straight lines</strong> are going to be added to the <strong>X-Y</strong> plane, such that every point is covered by at <strong>least </strong>one line.</p>
12+
13+
<p>Return <em>the <strong>minimum </strong>number of <strong>straight lines</strong> needed to cover all the points</em>.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong></p>
17+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2152.Minimum%20Number%20of%20Lines%20to%20Cover%20Points/images/image-20220123200023-1.png" style="width: 350px; height: 402px;" />
18+
<pre>
19+
<strong>Input:</strong> points = [[0,1],[2,3],[4,5],[4,3]]
20+
<strong>Output:</strong> 2
21+
<strong>Explanation:</strong> The minimum number of straight lines needed is two. One possible solution is to add:
22+
- One line connecting the point at (0, 1) to the point at (4, 5).
23+
- Another line connecting the point at (2, 3) to the point at (4, 3).
24+
</pre>
25+
26+
<p><strong>Example 2:</strong></p>
27+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2152.Minimum%20Number%20of%20Lines%20to%20Cover%20Points/images/image-20220123200057-3.png" style="width: 350px; height: 480px;" />
28+
<pre>
29+
<strong>Input:</strong> points = [[0,2],[-2,-2],[1,4]]
30+
<strong>Output:</strong> 1
31+
<strong>Explanation:</strong> The minimum number of straight lines needed is one. The only solution is to add:
32+
- One line connecting the point at (-2, -2) to the point at (1, 4).
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>1 &lt;= points.length &lt;= 10</code></li>
40+
<li><code>points[i].length == 2</code></li>
41+
<li><code>-100 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 100</code></li>
42+
<li>All the <code>points</code> are <strong>unique</strong>.</li>
43+
</ul>
44+
45+
## 解法
46+
47+
<!-- 这里可写通用的实现逻辑 -->
48+
49+
<!-- tabs:start -->
50+
51+
### **Python3**
52+
53+
<!-- 这里可写当前语言的特殊实现逻辑 -->
54+
55+
```python
56+
57+
```
58+
59+
### **Java**
60+
61+
<!-- 这里可写当前语言的特殊实现逻辑 -->
62+
63+
```java
64+
65+
```
66+
67+
### **TypeScript**
68+
69+
```ts
70+
71+
```
72+
73+
### **...**
74+
75+
```
76+
77+
```
78+
79+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# [2152. Minimum Number of Lines to Cover Points](https://leetcode.com/problems/minimum-number-of-lines-to-cover-points)
2+
3+
[中文文档](/solution/2100-2199/2152.Minimum%20Number%20of%20Lines%20to%20Cover%20Points/README.md)
4+
5+
## Description
6+
7+
<p>You are given an array <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on an <strong>X-Y </strong>plane.</p>
8+
9+
<p><strong>Straight lines</strong> are going to be added to the <strong>X-Y</strong> plane, such that every point is covered by at <strong>least </strong>one line.</p>
10+
11+
<p>Return <em>the <strong>minimum </strong>number of <strong>straight lines</strong> needed to cover all the points</em>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2152.Minimum%20Number%20of%20Lines%20to%20Cover%20Points/images/image-20220123200023-1.png" style="width: 350px; height: 402px;" />
16+
<pre>
17+
<strong>Input:</strong> points = [[0,1],[2,3],[4,5],[4,3]]
18+
<strong>Output:</strong> 2
19+
<strong>Explanation:</strong> The minimum number of straight lines needed is two. One possible solution is to add:
20+
- One line connecting the point at (0, 1) to the point at (4, 5).
21+
- Another line connecting the point at (2, 3) to the point at (4, 3).
22+
</pre>
23+
24+
<p><strong>Example 2:</strong></p>
25+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2152.Minimum%20Number%20of%20Lines%20to%20Cover%20Points/images/image-20220123200057-3.png" style="width: 350px; height: 480px;" />
26+
<pre>
27+
<strong>Input:</strong> points = [[0,2],[-2,-2],[1,4]]
28+
<strong>Output:</strong> 1
29+
<strong>Explanation:</strong> The minimum number of straight lines needed is one. The only solution is to add:
30+
- One line connecting the point at (-2, -2) to the point at (1, 4).
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= points.length &lt;= 10</code></li>
38+
<li><code>points[i].length == 2</code></li>
39+
<li><code>-100 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 100</code></li>
40+
<li>All the <code>points</code> are <strong>unique</strong>.</li>
41+
</ul>
42+
43+
## Solutions
44+
45+
<!-- tabs:start -->
46+
47+
### **Python3**
48+
49+
```python
50+
51+
```
52+
53+
### **Java**
54+
55+
```java
56+
57+
```
58+
59+
### **TypeScript**
60+
61+
```ts
62+
63+
```
64+
65+
### **...**
66+
67+
```
68+
69+
```
70+
71+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# [2153. The Number of Passengers in Each Bus II](https://leetcode-cn.com/problems/the-number-of-passengers-in-each-bus-ii)
2+
3+
[English Version](/solution/2100-2199/2153.The%20Number%20of%20Passengers%20in%20Each%20Bus%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Buses</code></p>
10+
11+
<pre>
12+
+--------------+------+
13+
| Column Name | Type |
14+
+--------------+------+
15+
| bus_id | int |
16+
| arrival_time | int |
17+
| capacity | int |
18+
+--------------+------+
19+
bus_id is the primary key column for this table.
20+
Each row of this table contains information about the arrival time of a bus at the Leetcode station and its capacity (i.e., the number of empty seats it has).
21+
There will be no two buses that arrive at the same time and capacity will be a positive integer.
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
26+
<p>Table: <code>Passengers</code></p>
27+
28+
<pre>
29+
+--------------+------+
30+
| Column Name | Type |
31+
+--------------+------+
32+
| passenger_id | int |
33+
| arrival_time | int |
34+
+--------------+------+
35+
passenger_id is the primary key column for this table.
36+
Each row of this table contains information about the arrival time of a passenger at the Leetcode station.
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
41+
<p>Buses and passengers arrive at the Leetcode station. If a bus arrives at the station at a time <code>t<sub>bus</sub></code> and a passenger arrived at a time <code>t<sub>passenger</sub></code> where <code>t<sub>passenger</sub> &lt;= t<sub>bus</sub></code> and the passenger did not catch any bus, the passenger will use that bus. In addition, each bus has a capacity. If at the moment the bus arrives at the station there are more passengers waiting than its capacity <code>capacity</code>, only <code>capacity</code> passengers will use the bus.</p>
42+
43+
<p>Write an SQL query to report the number of users that used each bus.</p>
44+
45+
<p>Return the result table ordered by <code>bus_id</code> in <strong>ascending order</strong>.</p>
46+
47+
<p>The query result format is in the following example.</p>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Example 1:</strong></p>
51+
52+
<pre>
53+
<strong>Input:</strong>
54+
Buses table:
55+
+--------+--------------+----------+
56+
| bus_id | arrival_time | capacity |
57+
+--------+--------------+----------+
58+
| 1 | 2 | 1 |
59+
| 2 | 4 | 10 |
60+
| 3 | 7 | 2 |
61+
+--------+--------------+----------+
62+
Passengers table:
63+
+--------------+--------------+
64+
| passenger_id | arrival_time |
65+
+--------------+--------------+
66+
| 11 | 1 |
67+
| 12 | 1 |
68+
| 13 | 5 |
69+
| 14 | 6 |
70+
| 15 | 7 |
71+
+--------------+--------------+
72+
<strong>Output:</strong>
73+
+--------+----------------+
74+
| bus_id | passengers_cnt |
75+
+--------+----------------+
76+
| 1 | 1 |
77+
| 2 | 1 |
78+
| 3 | 2 |
79+
+--------+----------------+
80+
<strong>Explanation:</strong>
81+
- Passenger 11 arrives at time 1.
82+
- Passenger 12 arrives at time 1.
83+
- Bus 1 arrives at time 2 and collects passenger 11 as it has one empty seat.
84+
85+
- Bus 2 arrives at time 4 and collects passenger 12 as it has ten empty seats.
86+
87+
- Passenger 12 arrives at time 5.
88+
- Passenger 13 arrives at time 6.
89+
- Passenger 14 arrives at time 7.
90+
- Bus 3 arrives at time 7 and collects passengers 12 and 13 as it has two empty seats.
91+
</pre>
92+
93+
## 解法
94+
95+
<!-- 这里可写通用的实现逻辑 -->
96+
97+
<!-- tabs:start -->
98+
99+
### **SQL**
100+
101+
<!-- 这里可写当前语言的特殊实现逻辑 -->
102+
103+
```sql
104+
105+
```
106+
107+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# [2153. The Number of Passengers in Each Bus II](https://leetcode.com/problems/the-number-of-passengers-in-each-bus-ii)
2+
3+
[中文文档](/solution/2100-2199/2153.The%20Number%20of%20Passengers%20in%20Each%20Bus%20II/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Buses</code></p>
8+
9+
<pre>
10+
+--------------+------+
11+
| Column Name | Type |
12+
+--------------+------+
13+
| bus_id | int |
14+
| arrival_time | int |
15+
| capacity | int |
16+
+--------------+------+
17+
bus_id is the primary key column for this table.
18+
Each row of this table contains information about the arrival time of a bus at the Leetcode station and its capacity (i.e., the number of empty seats it has).
19+
There will be no two buses that arrive at the same time and capacity will be a positive integer.
20+
</pre>
21+
22+
<p>&nbsp;</p>
23+
24+
<p>Table: <code>Passengers</code></p>
25+
26+
<pre>
27+
+--------------+------+
28+
| Column Name | Type |
29+
+--------------+------+
30+
| passenger_id | int |
31+
| arrival_time | int |
32+
+--------------+------+
33+
passenger_id is the primary key column for this table.
34+
Each row of this table contains information about the arrival time of a passenger at the Leetcode station.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
39+
<p>Buses and passengers arrive at the Leetcode station. If a bus arrives at the station at a time <code>t<sub>bus</sub></code> and a passenger arrived at a time <code>t<sub>passenger</sub></code> where <code>t<sub>passenger</sub> &lt;= t<sub>bus</sub></code> and the passenger did not catch any bus, the passenger will use that bus. In addition, each bus has a capacity. If at the moment the bus arrives at the station there are more passengers waiting than its capacity <code>capacity</code>, only <code>capacity</code> passengers will use the bus.</p>
40+
41+
<p>Write an SQL query to report the number of users that used each bus.</p>
42+
43+
<p>Return the result table ordered by <code>bus_id</code> in <strong>ascending order</strong>.</p>
44+
45+
<p>The query result format is in the following example.</p>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Example 1:</strong></p>
49+
50+
<pre>
51+
<strong>Input:</strong>
52+
Buses table:
53+
+--------+--------------+----------+
54+
| bus_id | arrival_time | capacity |
55+
+--------+--------------+----------+
56+
| 1 | 2 | 1 |
57+
| 2 | 4 | 10 |
58+
| 3 | 7 | 2 |
59+
+--------+--------------+----------+
60+
Passengers table:
61+
+--------------+--------------+
62+
| passenger_id | arrival_time |
63+
+--------------+--------------+
64+
| 11 | 1 |
65+
| 12 | 1 |
66+
| 13 | 5 |
67+
| 14 | 6 |
68+
| 15 | 7 |
69+
+--------------+--------------+
70+
<strong>Output:</strong>
71+
+--------+----------------+
72+
| bus_id | passengers_cnt |
73+
+--------+----------------+
74+
| 1 | 1 |
75+
| 2 | 1 |
76+
| 3 | 2 |
77+
+--------+----------------+
78+
<strong>Explanation:</strong>
79+
- Passenger 11 arrives at time 1.
80+
- Passenger 12 arrives at time 1.
81+
- Bus 1 arrives at time 2 and collects passenger 11 as it has one empty seat.
82+
83+
- Bus 2 arrives at time 4 and collects passenger 12 as it has ten empty seats.
84+
85+
- Passenger 12 arrives at time 5.
86+
- Passenger 13 arrives at time 6.
87+
- Passenger 14 arrives at time 7.
88+
- Bus 3 arrives at time 7 and collects passengers 12 and 13 as it has two empty seats.
89+
</pre>
90+
91+
## Solutions
92+
93+
<!-- tabs:start -->
94+
95+
### **SQL**
96+
97+
```sql
98+
99+
```
100+
101+
<!-- tabs:end -->

0 commit comments

Comments
 (0)