Skip to content

Commit 389e387

Browse files
committed
chore: add new lc problem
1 parent efa4030 commit 389e387

File tree

9 files changed

+211
-15
lines changed

9 files changed

+211
-15
lines changed

lcof/面试题54. 二叉搜索树的第k大节点/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
1. 中序遍历,并使用数组存储遍历结果。
4646
2. 遍历结束,返回 `arr[arr.length - k]`
4747

48-
*优化*
48+
_优化_
4949

5050
其中,只关注**第 k 大节点的值**,可以选择倒序遍历,记录当前遍历节点的数量,当数量为 `k` 时,记录当前节点值做为返回值即可,而无需记录所有的遍历结果。
5151

lcof2/剑指 Offer II 023. 两个链表的第一个重合节点/Solution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
function getIntersectionNode(
1414
headA: ListNode | null,
15-
headB: ListNode | null
15+
headB: ListNode | null,
1616
): ListNode | null {
1717
let p1: ListNode | null = headA;
1818
let p2: ListNode | null = headB;

lcof2/剑指 Offer II 113. 课程顺序/Solution.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function findOrder(numCourses: number, prerequisites: number[][]): number[] {
2-
let edges = Array.from({ length: numCourses }, () => ([]));
2+
let edges = Array.from({ length: numCourses }, () => []);
33
let indeg = new Array(numCourses).fill(0);
44
for (let [b, a] of prerequisites) {
55
edges[a].push(b);
@@ -25,4 +25,4 @@ function findOrder(numCourses: number, prerequisites: number[][]): number[] {
2525
}
2626
}
2727
return ans.length == numCourses ? ans : [];
28-
};
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# [2173. Longest Winning Streak](https://leetcode-cn.com/problems/longest-winning-streak)
2+
3+
[English Version](/solution/2100-2199/2173.Longest%20Winning%20Streak/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Matches</code></p>
10+
11+
<pre>
12+
+-------------+------+
13+
| Column Name | Type |
14+
+-------------+------+
15+
| player_id | int |
16+
| match_day | date |
17+
| result | enum |
18+
+-------------+------+
19+
(player_id, match_day) is the primary key for this table.
20+
Each row of this table contains the ID of a player, the day of the match they played, and the result of that match.
21+
The result column is an ENUM type of (&#39;Win&#39;, &#39;Draw&#39;, &#39;Lose&#39;).
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
26+
<p>The winning streak of a player is the number of consecutive wins uninterrupted by draws or losses.</p>
27+
28+
<p>Write an SQL query to count the longest winning streak for each player.</p>
29+
30+
<p>Return the result table in <strong>any order</strong>.</p>
31+
32+
<p>The query result format is in the following example.</p>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Example 1:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong>
39+
Matches table:
40+
+-----------+------------+--------+
41+
| player_id | match_day | result |
42+
+-----------+------------+--------+
43+
| 1 | 2022-01-17 | Win |
44+
| 1 | 2022-01-18 | Win |
45+
| 1 | 2022-01-25 | Win |
46+
| 1 | 2022-01-31 | Draw |
47+
| 1 | 2022-02-08 | Win |
48+
| 2 | 2022-02-06 | Lose |
49+
| 2 | 2022-02-08 | Lose |
50+
| 3 | 2022-03-30 | Win |
51+
+-----------+------------+--------+
52+
<strong>Output:</strong>
53+
+-----------+----------------+
54+
| player_id | longest_streak |
55+
+-----------+----------------+
56+
| 1 | 3 |
57+
| 2 | 0 |
58+
| 3 | 1 |
59+
+-----------+----------------+
60+
<strong>Explanation:</strong>
61+
Player 1:
62+
From 2022-01-17 to 2022-01-25, player 1 won 3 consecutive matches.
63+
On 2022-01-31, player 1 had a draw.
64+
On 2022-02-08, player 1 won a match.
65+
The longest winning streak was 3 matches.
66+
67+
Player 2:
68+
From 2022-02-06 to 2022-02-08, player 2 lost 2 consecutive matches.
69+
The longest winning streak was 0 matches.
70+
71+
Player 3:
72+
On 2022-03-30, player 3 won a match.
73+
The longest winning streak was 1 match.
74+
</pre>
75+
76+
<p>&nbsp;</p>
77+
<p><strong>Follow up:</strong> If we are interested in calculating the longest streak without losing (i.e., win or draw), how will your solution change?</p>
78+
79+
## 解法
80+
81+
<!-- 这里可写通用的实现逻辑 -->
82+
83+
<!-- tabs:start -->
84+
85+
### **SQL**
86+
87+
<!-- 这里可写当前语言的特殊实现逻辑 -->
88+
89+
```sql
90+
91+
```
92+
93+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# [2173. Longest Winning Streak](https://leetcode.com/problems/longest-winning-streak)
2+
3+
[中文文档](/solution/2100-2199/2173.Longest%20Winning%20Streak/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Matches</code></p>
8+
9+
<pre>
10+
+-------------+------+
11+
| Column Name | Type |
12+
+-------------+------+
13+
| player_id | int |
14+
| match_day | date |
15+
| result | enum |
16+
+-------------+------+
17+
(player_id, match_day) is the primary key for this table.
18+
Each row of this table contains the ID of a player, the day of the match they played, and the result of that match.
19+
The result column is an ENUM type of (&#39;Win&#39;, &#39;Draw&#39;, &#39;Lose&#39;).
20+
</pre>
21+
22+
<p>&nbsp;</p>
23+
24+
<p>The winning streak of a player is the number of consecutive wins uninterrupted by draws or losses.</p>
25+
26+
<p>Write an SQL query to count the longest winning streak for each player.</p>
27+
28+
<p>Return the result table in <strong>any order</strong>.</p>
29+
30+
<p>The query result format is in the following example.</p>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Example 1:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong>
37+
Matches table:
38+
+-----------+------------+--------+
39+
| player_id | match_day | result |
40+
+-----------+------------+--------+
41+
| 1 | 2022-01-17 | Win |
42+
| 1 | 2022-01-18 | Win |
43+
| 1 | 2022-01-25 | Win |
44+
| 1 | 2022-01-31 | Draw |
45+
| 1 | 2022-02-08 | Win |
46+
| 2 | 2022-02-06 | Lose |
47+
| 2 | 2022-02-08 | Lose |
48+
| 3 | 2022-03-30 | Win |
49+
+-----------+------------+--------+
50+
<strong>Output:</strong>
51+
+-----------+----------------+
52+
| player_id | longest_streak |
53+
+-----------+----------------+
54+
| 1 | 3 |
55+
| 2 | 0 |
56+
| 3 | 1 |
57+
+-----------+----------------+
58+
<strong>Explanation:</strong>
59+
Player 1:
60+
From 2022-01-17 to 2022-01-25, player 1 won 3 consecutive matches.
61+
On 2022-01-31, player 1 had a draw.
62+
On 2022-02-08, player 1 won a match.
63+
The longest winning streak was 3 matches.
64+
65+
Player 2:
66+
From 2022-02-06 to 2022-02-08, player 2 lost 2 consecutive matches.
67+
The longest winning streak was 0 matches.
68+
69+
Player 3:
70+
On 2022-03-30, player 3 won a match.
71+
The longest winning streak was 1 match.
72+
</pre>
73+
74+
<p>&nbsp;</p>
75+
<p><strong>Follow up:</strong> If we are interested in calculating the longest streak without losing (i.e., win or draw), how will your solution change?</p>
76+
77+
## Solutions
78+
79+
<!-- tabs:start -->
80+
81+
### **SQL**
82+
83+
```sql
84+
85+
```
86+
87+
<!-- tabs:end -->

0 commit comments

Comments
 (0)