Skip to content

Commit 36fb36c

Browse files
committed
feat: add new lc problems and solutions
1 parent 24b6349 commit 36fb36c

File tree

85 files changed

+3904
-104
lines changed

Some content is hidden

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

85 files changed

+3904
-104
lines changed

solution/0100-0199/0182.Duplicate Emails/README.md

+33-12
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,50 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>编写一个 SQL 查询,查找&nbsp;<code>Person</code> 表中所有重复的电子邮箱。</p>
9+
<p><meta charset="UTF-8" /></p>
10+
11+
<p>表:&nbsp;<code>Person</code></p>
12+
13+
<pre>
14+
+-------------+---------+
15+
| Column Name | Type |
16+
+-------------+---------+
17+
| id | int |
18+
| email | varchar |
19+
+-------------+---------+
20+
id 是该表的主键列。
21+
此表的每一行都包含一封电子邮件。电子邮件不包含大写字母。
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
26+
<p>编写一个 SQL 查询来报告所有重复的电子邮件。 请注意,可以保证电子邮件字段不为 NULL。</p>
27+
28+
<p>以&nbsp;<strong>任意顺序&nbsp;</strong>返回结果表。</p>
1029

11-
<p><strong>示例:</strong></p>
30+
<p>查询结果格式如下例。</p>
1231

13-
<pre>+----+---------+
14-
| Id | Email |
32+
<p>&nbsp;</p>
33+
34+
<p><strong>示例&nbsp;1:</strong></p>
35+
36+
<pre>
37+
<strong>输入:</strong>
38+
Person 表:
39+
+----+---------+
40+
| id | email |
1541
+----+---------+
1642
| 1 | a@b.com |
1743
| 2 | c@d.com |
1844
| 3 | a@b.com |
1945
+----+---------+
20-
</pre>
21-
22-
<p>根据以上输入,你的查询应返回以下结果:</p>
23-
24-
<pre>+---------+
46+
<strong>输出:</strong>
47+
+---------+
2548
| Email |
2649
+---------+
2750
| a@b.com |
2851
+---------+
29-
</pre>
30-
31-
<p><strong>说明:</strong>所有电子邮箱都是小写字母。</p>
52+
<strong>解释:</strong> a@b.com 出现了两次。</pre>
3253

3354
## 解法
3455

solution/0100-0199/0184.Department Highest Salary/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Each row of this table indicates the ID, name, and salary of an employee. It als
3131
| id | int |
3232
| name | varchar |
3333
+-------------+---------+
34-
id is the primary key column for this table.
34+
id is the primary key column for this table. It is guaranteed that department name is not <code>NULL.</code>
3535
Each row of this table indicates the ID of a department and its name.
3636
</pre>
3737

solution/0200-0299/0245.Shortest Word Distance III/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定一个字符串数组&nbsp;<code>wordsDict</code> 和两个字符串 <code>word1</code> 和 <code>word2</code> ,返回列表中这两个单词之间的最短距离。</p>
9+
<p>给定一个字符串数组&nbsp;<code>wordsDict</code> 和两个字符串 <code>word1</code> 和 <code>word2</code> ,返回这两个单词在列表中出现的最短距离。</p>
1010

1111
<p>注意:<code>word1</code> 和 <code>word2</code>&nbsp;是有可能相同的,并且它们将分别表示为列表中 <strong>两个独立的单词</strong> 。</p>
1212

1313
<p>&nbsp;</p>
1414

15-
<p><strong>示例 1:</strong></p>
15+
<p><strong class="example">示例 1:</strong></p>
1616

1717
<pre>
1818
<strong>输入:</strong>wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding"
1919
<strong>输出:</strong>1
2020
</pre>
2121

22-
<p><strong>示例 2:</strong></p>
22+
<p><strong class="example">示例 2:</strong></p>
2323

2424
<pre>
2525
<strong>输入:</strong>wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "makes"

solution/0400-0499/0464.Can I Win/README.md

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

1313
<p>例如,两个玩家可以轮流从公共整数池中抽取从 1 到 15 的整数(不放回),直到累计整数和 &gt;= 100。</p>
1414

15-
<p>给定两个整数&nbsp;<code>maxChoosableInteger</code>&nbsp;(整数池中可选择的最大数)和&nbsp;<code>desiredTotal</code>(累计和),若先出手的玩家是否能稳赢则返回 <code>true</code>&nbsp;,否则返回 <code>false</code> 。假设两位玩家游戏时都表现 <strong>最佳</strong> 。</p>
15+
<p>给定两个整数&nbsp;<code>maxChoosableInteger</code>&nbsp;(整数池中可选择的最大数)和&nbsp;<code>desiredTotal</code>(累计和),若先出手的玩家能稳赢则返回 <code>true</code>&nbsp;,否则返回 <code>false</code> 。假设两位玩家游戏时都表现 <strong>最佳</strong> 。</p>
1616

1717
<p>&nbsp;</p>
1818

solution/0500-0599/0585.Investments in 2016/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pid is the primary key column for this table.
2020
Each row of this table contains information about one policy where:
2121
pid is the policyholder&#39;s policy ID.
2222
tiv_2015 is the total investment value in 2015 and tiv_2016 is the total investment value in 2016.
23-
lat is the latitude of the policy holder&#39;s city.
24-
lon is the longitude of the policy holder&#39;s city.
23+
lat is the latitude of the policy holder&#39;s city. It&#39;s guaranteed that lat is not NULL.
24+
lon is the longitude of the policy holder&#39;s city. It&#39;s guaranteed that lon is not NULL.
2525
</pre>
2626

2727
<p>&nbsp;</p>

solution/0900-0999/0913.Cat and Mouse/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<li><code>0 &lt;= graph[i][j] &lt; graph.length</code></li>
5858
<li><code>graph[i][j] != i</code></li>
5959
<li><code>graph[i]</code> 互不相同</li>
60-
<li>猫和老鼠在游戏中总是移动</li>
60+
<li>猫和老鼠在游戏中总是可以移动</li>
6161
</ul>
6262

6363
## 解法

solution/1000-1099/1011.Capacity To Ship Packages Within D Days/README_EN.md

+2-30
Original file line numberDiff line numberDiff line change
@@ -11,78 +11,50 @@
1111
<p>Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within <code>days</code> days.</p>
1212

1313
<p>&nbsp;</p>
14-
1514
<p><strong class="example">Example 1:</strong></p>
1615

1716
<pre>
18-
1917
<strong>Input:</strong> weights = [1,2,3,4,5,6,7,8,9,10], days = 5
20-
2118
<strong>Output:</strong> 15
22-
2319
<strong>Explanation:</strong> A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:
24-
2520
1st day: 1, 2, 3, 4, 5
26-
2721
2nd day: 6, 7
28-
2922
3rd day: 8
30-
3123
4th day: 9
32-
3324
5th day: 10
3425

35-
36-
3726
Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.
38-
3927
</pre>
4028

4129
<p><strong class="example">Example 2:</strong></p>
4230

4331
<pre>
44-
4532
<strong>Input:</strong> weights = [3,2,2,4,1,4], days = 3
46-
4733
<strong>Output:</strong> 6
48-
4934
<strong>Explanation:</strong> A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:
50-
5135
1st day: 3, 2
52-
5336
2nd day: 2, 4
54-
5537
3rd day: 1, 4
56-
5738
</pre>
5839

5940
<p><strong class="example">Example 3:</strong></p>
6041

6142
<pre>
62-
6343
<strong>Input:</strong> weights = [1,2,3,1,1], days = 4
64-
6544
<strong>Output:</strong> 3
66-
6745
<strong>Explanation:</strong>
68-
6946
1st day: 1
70-
7147
2nd day: 2
72-
7348
3rd day: 3
74-
7549
4th day: 1, 1
76-
7750
</pre>
7851

7952
<p>&nbsp;</p>
80-
8153
<p><strong>Constraints:</strong></p>
8254

8355
<ul>
84-
<li><code>1 &lt;= days &lt;= weights.length &lt;= 5 * 10<sup>4</sup></code></li>
85-
<li><code>1 &lt;= weights[i] &lt;= 500</code></li>
56+
<li><code>1 &lt;= days &lt;= weights.length &lt;= 5 * 10<sup>4</sup></code></li>
57+
<li><code>1 &lt;= weights[i] &lt;= 500</code></li>
8658
</ul>
8759

8860
## Solutions

solution/1000-1099/1031.Maximum Sum of Two Non-Overlapping Subarrays/README.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,47 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给出非负整数数组 <code>A</code> ,返回两个非重叠(连续)子数组中元素的最大和,子数组的长度分别为 <code>L</code> 和 <code>M</code>。(这里需要澄清的是,长为 L 的子数组可以出现在长为 M 的子数组之前或之后。)</p>
9+
<p>给你一个整数数组 <code>nums</code> 和两个整数 <code>firstLen</code> 和 <code>secondLen</code>,请你找出并返回两个非重叠<strong> 子数组 </strong>中元素的最大和<em>,</em>长度分别为 <code>firstLen</code> 和 <code>secondLen</code> 。</p>
1010

11-
<p>从形式上看,返回最大的 <code>V</code>,而 <code>V = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1])</code> 并满足下列条件之一:</p>
11+
<p>长度为 <code>firstLen</code> 的子数组可以出现在长为 <code>secondLen</code> 的子数组之前或之后,但二者必须是不重叠的。</p>
1212

13-
<p>&nbsp;</p>
14-
15-
<ul>
16-
<li><code>0 &lt;= i &lt; i + L - 1 &lt; j &lt; j + M - 1 &lt; A.length</code>, <strong>或</strong></li>
17-
<li><code>0 &lt;= j &lt; j + M - 1 &lt; i &lt; i + L - 1 &lt; A.length</code>.</li>
18-
</ul>
13+
<p>子数组是数组的一个 <strong>连续</strong> 部分。</p>
1914

2015
<p>&nbsp;</p>
2116

2217
<p><strong>示例 1:</strong></p>
2318

2419
<pre>
25-
<strong>输入:</strong>A = [0,6,5,2,2,5,1,9,4], L = 1, M = 2
20+
<strong>输入:</strong>nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2
2621
<strong>输出:</strong>20
2722
<strong>解释:</strong>子数组的一种选择中,[9] 长度为 1,[6,5] 长度为 2。
2823
</pre>
2924

3025
<p><strong>示例 2:</strong></p>
3126

3227
<pre>
33-
<strong>输入:</strong>A = [3,8,1,3,2,1,8,9,0], L = 3, M = 2
28+
<strong>输入:</strong>nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2
3429
<strong>输出:</strong>29
3530
<strong>解释:</strong>子数组的一种选择中,[3,8,1] 长度为 3,[8,9] 长度为 2。
3631
</pre>
3732

3833
<p><strong>示例 3:</strong></p>
3934

4035
<pre>
41-
<strong>输入:</strong>A = [2,1,5,6,0,9,5,0,3,8], L = 4, M = 3
36+
<strong>输入:</strong>nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3
4237
<strong>输出:</strong>31
43-
<strong>解释:</strong>子数组的一种选择中,[5,6,0,9] 长度为 4,[0,3,8] 长度为 3。</pre>
38+
<strong>解释:</strong>子数组的一种选择中,[5,6,0,9] 长度为 4,[0,3,8] 长度为 3。
39+
</pre>
4440

4541
<p>&nbsp;</p>
4642

4743
<p><strong>提示:</strong></p>
4844

4945
<ul>
50-
<li><code>L &gt;= 1</code></li>
51-
<li><code>M &gt;= 1</code></li>
52-
<li><code>L + M &lt;= A.length &lt;= 1000</code></li>
53-
<li><code>0 &lt;= A[i] &lt;= 1000</code></li>
46+
<li><code>1 &lt;= firstLen, secondLen &lt;= 1000</code></li>
47+
<li><code>2 &lt;= firstLen + secondLen &lt;= 1000</code></li>
48+
<li><code>firstLen + secondLen &lt;= nums.length &lt;= 1000</code></li>
49+
<li><code>0 &lt;= nums[i] &lt;= 1000</code></li>
5450
</ul>
5551

5652
## 解法

solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| customer_id | int |
1414
| product_key | int |
1515
+-------------+---------+
16-
There is no primary key for this table. It may contain duplicates.
16+
There is no primary key for this table. It may contain duplicates. <code>customer_id</code> is not NULL<code>.</code>
1717
product_key is a foreign key to <code>Product</code> table.
1818
</pre>
1919

solution/1000-1099/1075.Project Employees I/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Each row of this table indicates that the employee with employee_id is working o
3030
| name | varchar |
3131
| experience_years | int |
3232
+------------------+---------+
33-
employee_id is the primary key of this table.
33+
employee_id is the primary key of this table. It&#39;s guaranteed that experience_years is not NULL.
3434
Each row of this table contains information about one employee.
3535
</pre>
3636

solution/1000-1099/1083.Sales Analysis II/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Each row of this table indicates the name and the price of each product.
3333
+-------------+---------+
3434
This table has no primary key, it can have repeated rows.
3535
product_id is a foreign key to the Product table.
36+
buyer_id is never NULL.
37+
sale_date is never NULL.
3638
Each row of this table contains some information about one sale.
3739
</pre>
3840

solution/1100-1199/1105.Filling Bookcase Shelves/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<p>&nbsp;</p>
2626

27-
<p><strong>示例 1:</strong></p>
27+
<p><strong class="example">示例 1:</strong></p>
2828

2929
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/images/shelves.png" style="width: 337px; height: 500px;" /></p>
3030

@@ -36,7 +36,7 @@
3636
第 2 本书不必放在第一层书架上。
3737
</pre>
3838

39-
<p><strong>示例 2:</strong></p>
39+
<p><strong class="example">示例 2:</strong></p>
4040

4141
<pre>
4242
<strong>输入:</strong> books = [[1,3],[2,4],[3,2]], shelfWidth = 6

solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| grade | int |
1616
+---------------+---------+
1717
(student_id, course_id) is the primary key of this table.
18+
grade is never NULL.
1819
</pre>
1920

2021
<p>&nbsp;</p>

solution/1100-1199/1113.Reported Posts/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
There is no primary key for this table, it may have duplicate rows.
2020
The action column is an ENUM type of (&#39;view&#39;, &#39;like&#39;, &#39;reaction&#39;, &#39;comment&#39;, &#39;report&#39;, &#39;share&#39;).
2121
The extra column has optional information about the action, such as a reason for the report or a type of reaction.
22+
extra is never NULL.
2223
</pre>
2324

2425
<p>&nbsp;</p>

solution/1200-1299/1247.Minimum Swaps to Make Strings Equal/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Note that you cannot swap s1[0] and s1[1] to make s1 equal to &quot;yx&quot;, ca
3939

4040
<ul>
4141
<li><code>1 &lt;= s1.length, s2.length &lt;= 1000</code></li>
42+
<li><code>s1.length == s2.length</code></li>
4243
<li><code>s1, s2</code> only contain <code>&#39;x&#39;</code> or <code>&#39;y&#39;</code>.</li>
4344
</ul>
4445

solution/1500-1599/1506.Find Root of N-Ary Tree/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定一棵 <a href="https://slack-redir.net/link?url=https%3A%2F%2Fleetcode.com%2Farticles%2Fintroduction-to-n-ary-trees" target="_blank">N 叉树</a> 的所有节点在一个数组  <code>Node[] tree</code> 中,树中每个节点都有 <strong>唯一的值</strong> 。</p>
9+
<p>给定一棵&nbsp;<a href="https://leetcode.cn/explore/learn/card/n-ary-tree/" target="_blank">N 叉树</a>&nbsp;的所有节点在一个数组&nbsp;&nbsp;<code>Node[] tree</code>&nbsp;中,树中每个节点都有 <strong>唯一的值</strong> 。</p>
1010

1111
<p>找到并返回 N 叉树的 <strong>根节点 </strong>。</p>
1212

13-
<p> </p>
13+
<p>&nbsp;</p>
1414

1515
<p><strong>自定义测试:</strong></p>
1616

@@ -29,9 +29,9 @@
2929
<li>驱动程序代码将接受返回的 <code>Node</code> 对象并对其进行序列化。如果序列化的结果和输入数据 <strong>相同</strong> ,则测试 <strong>通过</strong> 。</li>
3030
</ul>
3131

32-
<p> </p>
32+
<p>&nbsp;</p>
3333

34-
<p><strong>示例 1:</strong></p>
34+
<p><strong class="example">示例 1:</strong></p>
3535

3636
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/images/narytreeexample.png" style="width:250px" /></p>
3737

@@ -44,7 +44,7 @@
4444
findRoot 函数应该返回根 Node(1) ,驱动程序代码将序列化它并与输入数据进行比较。
4545
输入数据和序列化的 Node(1) 相同,因此测试通过。</pre>
4646

47-
<p><strong>示例 2:</strong></p>
47+
<p><strong class="example">示例 2:</strong></p>
4848

4949
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/images/sample_4_964.png" style="height:241px; width:296px" /></p>
5050

@@ -53,16 +53,16 @@ findRoot 函数应该返回根 Node(1) ,驱动程序代码将序列化它并
5353
<strong>输出:</strong>[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
5454
</pre>
5555

56-
<p> </p>
56+
<p>&nbsp;</p>
5757

5858
<p><strong>提示:</strong></p>
5959

6060
<ul>
61-
<li>节点的总个数在 <code>[1, 5*10^4]</code> 之间。</li>
61+
<li>节点的总个数在&nbsp;<code>[1,&nbsp;5*10^4]</code>&nbsp;之间。</li>
6262
<li>每个节点都有唯一的值。</li>
6363
</ul>
6464

65-
<p> </p>
65+
<p>&nbsp;</p>
6666

6767
<p><strong>进阶:</strong></p>
6868

0 commit comments

Comments
 (0)