Skip to content

Commit 66e1a30

Browse files
authored
feat: add weekly contest 430 (#3900)
1 parent 5ac1295 commit 66e1a30

File tree

41 files changed

+2227
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2227
-12
lines changed

solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tags:
2626

2727
<pre>
2828
<strong>输入: </strong>s = "abcabcbb"
29-
<strong>输出: </strong>3
29+
<strong>输出: </strong>3
3030
<strong>解释:</strong> 因为无重复字符的最长子串是 <code>"abc"</code>,所以其长度为 3。
3131
</pre>
3232

solution/0100-0199/0189.Rotate Array/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tags:
3838
<pre>
3939
<strong>输入:</strong>nums = [-1,-100,3,99], k = 2
4040
<strong>输出:</strong>[3,99,-1,-100]
41-
<strong>解释:</strong>
41+
<strong>解释:</strong>
4242
向右轮转 1 步: [99,-1,-100,3]
4343
向右轮转 2 步: [3,99,-1,-100]</pre>
4444

solution/0100-0199/0189.Rotate Array/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ rotate 3 steps to the right: [5,6,7,1,2,3,4]
3737
<pre>
3838
<strong>Input:</strong> nums = [-1,-100,3,99], k = 2
3939
<strong>Output:</strong> [3,99,-1,-100]
40-
<strong>Explanation:</strong>
40+
<strong>Explanation:</strong>
4141
rotate 1 steps to the right: [99,-1,-100,3]
4242
rotate 2 steps to the right: [3,99,-1,-100]
4343
</pre>

solution/0200-0299/0239.Sliding Window Maximum/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tags:
3030
<pre>
3131
<strong>Input:</strong> nums = [1,3,-1,-3,5,3,6,7], k = 3
3232
<strong>Output:</strong> [3,3,5,5,6,7]
33-
<strong>Explanation:</strong>
33+
<strong>Explanation:</strong>
3434
Window position Max
3535
--------------- -----
3636
[1 3 -1] -3 5 3 6 7 <strong>3</strong>

solution/1300-1399/1366.Rank Teams by Votes/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ C 队获得三票「排位第二」,两票「排位第三」。
5555
<strong>输入:</strong>votes = ["WXYZ","XYZW"]
5656
<strong>输出:</strong>"XWYZ"
5757
<strong>解释:</strong>
58-
X 队在并列僵局打破后成为排名第一的团队。X 队和 W 队的「排位第一」票数一样,但是 X 队有一票「排位第二」,而 W 没有获得「排位第二」。
58+
X 队在并列僵局打破后成为排名第一的团队。X 队和 W 队的「排位第一」票数一样,但是 X 队有一票「排位第二」,而 W 没有获得「排位第二」。
5959
</pre>
6060

6161
<p><strong class="example">示例 3:</strong></p>

solution/1300-1399/1366.Rank Teams by Votes/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tags:
3636
<pre>
3737
<strong>Input:</strong> votes = [&quot;ABC&quot;,&quot;ACB&quot;,&quot;ABC&quot;,&quot;ACB&quot;,&quot;ACB&quot;]
3838
<strong>Output:</strong> &quot;ACB&quot;
39-
<strong>Explanation:</strong>
39+
<strong>Explanation:</strong>
4040
Team A was ranked first place by 5 voters. No other team was voted as first place, so team A is the first team.
4141
Team B was ranked second by 2 voters and ranked third by 3 voters.
4242
Team C was ranked second by 3 voters and ranked third by 2 voters.
@@ -49,7 +49,7 @@ As most of the voters ranked C second, team C is the second team, and team B is
4949
<strong>Input:</strong> votes = [&quot;WXYZ&quot;,&quot;XYZW&quot;]
5050
<strong>Output:</strong> &quot;XWYZ&quot;
5151
<strong>Explanation:</strong>
52-
X is the winner due to the tie-breaking rule. X has the same votes as W for the first position, but X has one vote in the second position, while W does not have any votes in the second position.
52+
X is the winner due to the tie-breaking rule. X has the same votes as W for the first position, but X has one vote in the second position, while W does not have any votes in the second position.
5353
</pre>
5454

5555
<p><strong class="example">Example 3:</strong></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
comments: true
3+
difficulty: 困难
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README.md
5+
tags:
6+
- 数据库
7+
---
8+
9+
<!-- problem:start -->
10+
11+
# [3401. Find Circular Gift Exchange Chains 🔒](https://leetcode.cn/problems/find-circular-gift-exchange-chains)
12+
13+
[English Version](/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README_EN.md)
14+
15+
## 题目描述
16+
17+
<!-- description:start -->
18+
19+
<p>Table: <code>SecretSanta</code></p>
20+
21+
<pre>
22+
+-------------+------+
23+
| Column Name | Type |
24+
+-------------+------+
25+
| giver_id | int |
26+
| receiver_id | int |
27+
| gift_value | int |
28+
+-------------+------+
29+
(giver_id, receiver_id) is the unique key for this table.
30+
Each row represents a record of a gift exchange between two employees, giver_id represents the employee who gives a gift, receiver_id represents the employee who receives the gift and gift_value represents the value of the gift given.
31+
</pre>
32+
33+
<p>Write a solution to find the <strong>total gift value</strong> and <strong>length</strong> of<strong> circular chains</strong> of Secret Santa gift exchanges:</p>
34+
35+
<p>A <strong>circular chain</strong> is defined as a series of exchanges where:</p>
36+
37+
<ul>
38+
<li>Each employee gives a gift to <strong>exactly one</strong> other employee.</li>
39+
<li>Each employee receives a gift <strong>from exactly</strong> one other employee.</li>
40+
<li>The exchanges form a continuous <strong>loop</strong> (e.g., employee A gives a gift to B, B gives to C, and C gives back to A).</li>
41+
</ul>
42+
43+
<p>Return <em>the result ordered by the chain length and total gift value of the chain in&nbsp;<strong>descending</strong> order</em>.&nbsp;</p>
44+
45+
<p>The result format is in the following example.</p>
46+
47+
<p>&nbsp;</p>
48+
<p><strong class="example">Example:</strong></p>
49+
50+
<div class="example-block">
51+
<p><strong>Input:</strong></p>
52+
53+
<p>SecretSanta table:</p>
54+
55+
<pre class="example-io">
56+
+----------+-------------+------------+
57+
| giver_id | receiver_id | gift_value |
58+
+----------+-------------+------------+
59+
| 1 | 2 | 20 |
60+
| 2 | 3 | 30 |
61+
| 3 | 1 | 40 |
62+
| 4 | 5 | 25 |
63+
| 5 | 4 | 35 |
64+
+----------+-------------+------------+
65+
</pre>
66+
67+
<p><strong>Output:</strong></p>
68+
69+
<pre class="example-io">
70+
+----------+--------------+------------------+
71+
| chain_id | chain_length | total_gift_value |
72+
+----------+--------------+------------------+
73+
| 1 | 3 | 90 |
74+
| 2 | 2 | 60 |
75+
+----------+--------------+------------------+
76+
</pre>
77+
78+
<p><strong>Explanation:</strong></p>
79+
80+
<ul>
81+
<li><strong>Chain 1</strong> involves employees 1, 2, and 3:
82+
83+
<ul>
84+
<li>Employee 1 gives a gift to 2, employee 2 gives a gift to 3, and employee 3 gives a gift to 1.</li>
85+
<li>Total gift value for this chain = 20 + 30 + 40 = 90.</li>
86+
</ul>
87+
</li>
88+
<li><strong>Chain 2</strong> involves employees 4 and 5:
89+
<ul>
90+
<li>Employee 4 gives a gift to 5, and employee 5 gives a gift to 4.</li>
91+
<li>Total gift value for this chain = 25 + 35 = 60.</li>
92+
</ul>
93+
</li>
94+
95+
</ul>
96+
97+
<p>The result table is ordered by the chain length and total gift value of the chain in descending order.</p>
98+
</div>
99+
100+
<!-- description:end -->
101+
102+
## 解法
103+
104+
<!-- solution:start -->
105+
106+
### 方法一
107+
108+
<!-- tabs:start -->
109+
110+
#### MySQL
111+
112+
```sql
113+
114+
```
115+
116+
<!-- tabs:end -->
117+
118+
<!-- solution:end -->
119+
120+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
comments: true
3+
difficulty: Hard
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README_EN.md
5+
tags:
6+
- Database
7+
---
8+
9+
<!-- problem:start -->
10+
11+
# [3401. Find Circular Gift Exchange Chains 🔒](https://leetcode.com/problems/find-circular-gift-exchange-chains)
12+
13+
[中文文档](/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README.md)
14+
15+
## Description
16+
17+
<!-- description:start -->
18+
19+
<p>Table: <code>SecretSanta</code></p>
20+
21+
<pre>
22+
+-------------+------+
23+
| Column Name | Type |
24+
+-------------+------+
25+
| giver_id | int |
26+
| receiver_id | int |
27+
| gift_value | int |
28+
+-------------+------+
29+
(giver_id, receiver_id) is the unique key for this table.
30+
Each row represents a record of a gift exchange between two employees, giver_id represents the employee who gives a gift, receiver_id represents the employee who receives the gift and gift_value represents the value of the gift given.
31+
</pre>
32+
33+
<p>Write a solution to find the <strong>total gift value</strong> and <strong>length</strong> of<strong> circular chains</strong> of Secret Santa gift exchanges:</p>
34+
35+
<p>A <strong>circular chain</strong> is defined as a series of exchanges where:</p>
36+
37+
<ul>
38+
<li>Each employee gives a gift to <strong>exactly one</strong> other employee.</li>
39+
<li>Each employee receives a gift <strong>from exactly</strong> one other employee.</li>
40+
<li>The exchanges form a continuous <strong>loop</strong> (e.g., employee A gives a gift to B, B gives to C, and C gives back to A).</li>
41+
</ul>
42+
43+
<p>Return <em>the result ordered by the chain length and total gift value of the chain in&nbsp;<strong>descending</strong> order</em>.&nbsp;</p>
44+
45+
<p>The result format is in the following example.</p>
46+
47+
<p>&nbsp;</p>
48+
<p><strong class="example">Example:</strong></p>
49+
50+
<div class="example-block">
51+
<p><strong>Input:</strong></p>
52+
53+
<p>SecretSanta table:</p>
54+
55+
<pre class="example-io">
56+
+----------+-------------+------------+
57+
| giver_id | receiver_id | gift_value |
58+
+----------+-------------+------------+
59+
| 1 | 2 | 20 |
60+
| 2 | 3 | 30 |
61+
| 3 | 1 | 40 |
62+
| 4 | 5 | 25 |
63+
| 5 | 4 | 35 |
64+
+----------+-------------+------------+
65+
</pre>
66+
67+
<p><strong>Output:</strong></p>
68+
69+
<pre class="example-io">
70+
+----------+--------------+------------------+
71+
| chain_id | chain_length | total_gift_value |
72+
+----------+--------------+------------------+
73+
| 1 | 3 | 90 |
74+
| 2 | 2 | 60 |
75+
+----------+--------------+------------------+
76+
</pre>
77+
78+
<p><strong>Explanation:</strong></p>
79+
80+
<ul>
81+
<li><strong>Chain 1</strong> involves employees 1, 2, and 3:
82+
83+
<ul>
84+
<li>Employee 1 gives a gift to 2, employee 2 gives a gift to 3, and employee 3 gives a gift to 1.</li>
85+
<li>Total gift value for this chain = 20 + 30 + 40 = 90.</li>
86+
</ul>
87+
</li>
88+
<li><strong>Chain 2</strong> involves employees 4 and 5:
89+
<ul>
90+
<li>Employee 4 gives a gift to 5, and employee 5 gives a gift to 4.</li>
91+
<li>Total gift value for this chain = 25 + 35 = 60.</li>
92+
</ul>
93+
</li>
94+
95+
</ul>
96+
97+
<p>The result table is ordered by the chain length and total gift value of the chain in descending order.</p>
98+
</div>
99+
100+
<!-- description:end -->
101+
102+
## Solutions
103+
104+
<!-- solution:start -->
105+
106+
### Solution 1
107+
108+
<!-- tabs:start -->
109+
110+
#### MySQL
111+
112+
```sql
113+
114+
```
115+
116+
<!-- tabs:end -->
117+
118+
<!-- solution:end -->
119+
120+
<!-- problem:end -->

0 commit comments

Comments
 (0)