Skip to content

Commit d3f95fe

Browse files
authored
chore: update lc problems (doocs#2164)
1 parent ae4c9c2 commit d3f95fe

File tree

64 files changed

+698
-437
lines changed

Some content is hidden

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

64 files changed

+698
-437
lines changed

solution/0100-0199/0167.Two Sum II - Input Array Is Sorted/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
<p>你所设计的解决方案必须只使用常量级的额外空间。</p>
1616
&nbsp;
1717

18-
<p><strong>示例 1:</strong></p>
18+
<p><strong class="example">示例 1:</strong></p>
1919

2020
<pre>
2121
<strong>输入:</strong>numbers = [<strong><em>2</em></strong>,<strong><em>7</em></strong>,11,15], target = 9
2222
<strong>输出:</strong>[1,2]
2323
<strong>解释:</strong>2 与 7 之和等于目标数 9 。因此 index<sub>1</sub> = 1, index<sub>2</sub> = 2 。返回 [1, 2] 。</pre>
2424

25-
<p><strong>示例 2:</strong></p>
25+
<p><strong class="example">示例 2:</strong></p>
2626

2727
<pre>
2828
<strong>输入:</strong>numbers = [<strong><em>2</em></strong>,3,<strong><em>4</em></strong>], target = 6
2929
<strong>输出:</strong>[1,3]
3030
<strong>解释:</strong>2 与 4 之和等于目标数 6 。因此 index<sub>1</sub> = 1, index<sub>2</sub> = 3 。返回 [1, 3] 。</pre>
3131

32-
<p><strong>示例 3:</strong></p>
32+
<p><strong class="example">示例 3:</strong></p>
3333

3434
<pre>
3535
<strong>输入:</strong>numbers = [<strong><em>-1</em></strong>,<strong><em>0</em></strong>], target = -1

solution/0100-0199/0195.Tenth Line/README_EN.md

+15
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,41 @@
1111
<p>Assume that <code>file.txt</code> has the following content:</p>
1212

1313
<pre>
14+
1415
Line 1
16+
1517
Line 2
18+
1619
Line 3
20+
1721
Line 4
22+
1823
Line 5
24+
1925
Line 6
26+
2027
Line 7
28+
2129
Line 8
30+
2231
Line 9
32+
2333
Line 10
34+
2435
</pre>
2536

2637
<p>Your script should output the tenth line, which is:</p>
2738

2839
<pre>
40+
2941
Line 10
42+
3043
</pre>
3144

3245
<div class="spoilers"><b>Note:</b><br />
46+
3347
1. If the file contains less than 10 lines, what should you output?<br />
48+
3449
2. There&#39;s at least three different solutions. Try to explore all possibilities.</div>
3550

3651
## Solutions

solution/0200-0299/0255.Verify Preorder Sequence in Binary Search Tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [255. 验证前序遍历序列二叉搜索树](https://leetcode.cn/problems/verify-preorder-sequence-in-binary-search-tree)
1+
# [255. 验证二叉搜索树的前序遍历序列](https://leetcode.cn/problems/verify-preorder-sequence-in-binary-search-tree)
22

33
[English Version](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README_EN.md)
44

solution/0200-0299/0266.Palindrome Permutation/README.md

+27-10
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,39 @@
66

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

9-
<p>给定一个字符串,判断该字符串中是否可以通过重新排列组合,形成一个回文字符串。</p>
9+
<p>给你一个字符串 <code>s</code> ,如果该字符串的某个排列是 <strong>回文</strong> ,则返回 <code>true</code> ;否则,返回<em> </em><code>false</code><em> </em>。</p>
1010

11-
<p><strong>示例 1:</strong></p>
11+
<p>&nbsp;</p>
1212

13-
<pre><strong>输入:</strong> <code>&quot;code&quot;</code>
14-
<strong>输出:</strong> false</pre>
13+
<p><strong class="example">示例 1:</strong></p>
1514

16-
<p><strong>示例 2:</strong></p>
15+
<pre>
16+
<strong>输入:</strong>s = "code"
17+
<strong>输出:</strong>false
18+
</pre>
1719

18-
<pre><strong>输入:</strong> <code>&quot;aab&quot;</code>
19-
<strong>输出:</strong> true</pre>
20+
<p><strong class="example">示例 2:</strong></p>
2021

21-
<p><strong>示例 3:</strong></p>
22+
<pre>
23+
<strong>输入:</strong>s = "aab"
24+
<strong>输出:</strong>true
25+
</pre>
2226

23-
<pre><strong>输入:</strong> <code>&quot;carerac&quot;</code>
24-
<strong>输出:</strong> true</pre>
27+
<p><strong class="example">示例 3:</strong></p>
28+
29+
<pre>
30+
<strong>输入:</strong>s = "carerac"
31+
<strong>输出:</strong>true
32+
</pre>
33+
34+
<p>&nbsp;</p>
35+
36+
<p><strong>提示:</strong></p>
37+
38+
<ul>
39+
<li><code>1 &lt;= s.length &lt;= 5000</code></li>
40+
<li><code>s</code> 仅由小写英文字母组成</li>
41+
</ul>
2542

2643
## 解法
2744

solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<p>请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。</p>
1212

13-
<p><strong>提示: </strong>输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅 <a href="/faq/#binary-tree">LeetCode 序列化二叉树的格式</a>。你并非必须采取这种方式,你也可以采用其他的方法解决这个问题。</p>
13+
<p><strong>提示: </strong>输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅&nbsp;<a href="https://support.leetcode.cn/hc/kb/article/1567641/">LeetCode 序列化二叉树的格式</a>。你并非必须采取这种方式,你也可以采用其他的方法解决这个问题。</p>
1414

15-
<p> </p>
15+
<p>&nbsp;</p>
1616

1717
<p><strong>示例 1:</strong></p>
1818
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/images/serdeser.jpg" style="width: 442px; height: 324px;" />
@@ -42,13 +42,13 @@
4242
<strong>输出:</strong>[1,2]
4343
</pre>
4444

45-
<p> </p>
45+
<p>&nbsp;</p>
4646

4747
<p><strong>提示:</strong></p>
4848

4949
<ul>
5050
<li>树中结点数在范围 <code>[0, 10<sup>4</sup>]</code> 内</li>
51-
<li><code>-1000 <= Node.val <= 1000</code></li>
51+
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
5252
</ul>
5353

5454
## 解法

solution/0300-0399/0339.Nested List Weight Sum/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [339. 嵌套列表权重和](https://leetcode.cn/problems/nested-list-weight-sum)
1+
# [339. 嵌套列表加权和](https://leetcode.cn/problems/nested-list-weight-sum)
22

33
[English Version](/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README_EN.md)
44

solution/0300-0399/0364.Nested List Weight Sum II/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [364. 加权嵌套序列和 II](https://leetcode.cn/problems/nested-list-weight-sum-ii)
1+
# [364. 嵌套列表加权和 II](https://leetcode.cn/problems/nested-list-weight-sum-ii)
22

33
[English Version](/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README_EN.md)
44

solution/0300-0399/0373.Find K Pairs with Smallest Sums/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
<ul>
4848
<li><code>1 &lt;= nums1.length, nums2.length &lt;= 10<sup>5</sup></code></li>
4949
<li><code>-10<sup>9</sup> &lt;= nums1[i], nums2[i] &lt;= 10<sup>9</sup></code></li>
50-
<li><code>nums1</code> 和 <code>nums2</code> 均为升序排列</li>
51-
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
50+
<li><code>nums1</code> 和 <code>nums2</code> 均为 <strong>升序排列</strong></li>
51+
<li><meta charset="UTF-8" /><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
52+
<li><code>k &lt;=&nbsp;nums1.length *&nbsp;nums2.length</code></li>
5253
</ul>
5354

5455
## 解法

solution/0400-0499/0491.Non-decreasing Subsequences/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [491. 递增子序列](https://leetcode.cn/problems/non-decreasing-subsequences)
1+
# [491. 非递减子序列](https://leetcode.cn/problems/non-decreasing-subsequences)
22

33
[English Version](/solution/0400-0499/0491.Non-decreasing%20Subsequences/README_EN.md)
44

solution/0500-0599/0573.Squirrel Simulation/README.md

+41-21
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,50 @@
66

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

9-
<p>现在有一棵树,一只松鼠和一些坚果。位置由二维网格的单元格表示。你的目标是找到松鼠收集所有坚果的<strong>最小路程</strong>,且坚果是一颗接一颗地被放在树下。松鼠一次最多只能携带<strong>一颗</strong>坚果,松鼠可以向上,向下,向左和向右四个方向移动到相邻的单元格。移动次数表示路程。</p>
10-
11-
<p><strong>输入 1:</strong></p>
12-
13-
<pre><strong>输入:</strong>
14-
高度 : 5
15-
宽度 : 7
16-
树的位置 : [2,2]
17-
松鼠 : [4,4]
18-
坚果 : [[3,0], [2,5]]
19-
<strong>输出:</strong> 12
20-
<strong>解释:</strong>
21-
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0573.Squirrel%20Simulation/images/squirrel_simulation.png" style="width: 40%;">​​​​​
9+
<p>给你两个整数 <code>height</code> 和 <code>width</code> ,代表一个大小为 <code>height x width</code> 的花园。你还得到了以下信息:</p>
10+
11+
<ul>
12+
<li>一个数组 <code>tree</code> ,其中 <code>tree = [tree<sub>r</sub>, tree<sub>c</sub>]</code> 是花园中树的位置,</li>
13+
<li>一个数组 <code>squirrel</code> ,其中 <code>squirrel = [squirrel<sub>r</sub>, squirrel<sub>c</sub>]</code> 是花园中松鼠的位置,</li>
14+
<li>一个数组 <code>nuts</code> ,其中 <code>nuts[i] = [nut<sub>i<sub>r</sub></sub>, nut<sub>i<sub>c</sub></sub>]</code> 是花园中第 <code>i<sup>th</sup></code> 个坚果的位置。</li>
15+
</ul>
16+
17+
<p>松鼠一次最多只能携带一个坚果,并且能够向上、下、左、右四个方向移动到相邻的单元格。</p>
18+
19+
<p>返回松鼠收集所有坚果并逐一放在树下的 <strong>最小距离</strong> 。</p>
20+
21+
<p><strong>距离</strong> 是指移动的次数。</p>
22+
23+
<p>&nbsp;</p>
24+
25+
<p><strong class="example">示例 1:</strong></p>
26+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0573.Squirrel%20Simulation/images/squirrel1-grid.jpg" style="width: 573px; height: 413px;" />
27+
<pre>
28+
<strong>输入:</strong>height = 5, width = 7, tree = [2,2], squirrel = [4,4], nuts = [[3,0], [2,5]]
29+
<strong>输出:</strong>12
30+
<strong>解释:</strong>为实现最小的距离,松鼠应该先摘 [2, 5] 位置的坚果。
31+
</pre>
32+
33+
<p><strong class="example">示例 2:</strong></p>
34+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0573.Squirrel%20Simulation/images/squirrel2-grid.jpg" style="width: 253px; height: 93px;" />
35+
<pre>
36+
<strong>输入:</strong>height = 1, width = 3, tree = [0,1], squirrel = [0,0], nuts = [[0,2]]
37+
<strong>输出:</strong>3
2238
</pre>
2339

24-
<p><strong>注意:</strong></p>
40+
<p>&nbsp;</p>
41+
42+
<p><strong>提示:</strong></p>
2543

26-
<ol>
27-
<li>所有给定的位置不会重叠。</li>
28-
<li>松鼠一次最多只能携带一颗坚果。</li>
29-
<li>给定的坚果位置没有顺序。</li>
30-
<li>高度和宽度是正整数。 3 &lt;= 高度 * 宽度 &lt;= 10,000。</li>
31-
<li>给定的网格至少包含一颗坚果,唯一的一棵树和一只松鼠。</li>
32-
</ol>
44+
<ul>
45+
<li><code>1 &lt;= height, width &lt;= 100</code></li>
46+
<li><code>tree.length == 2</code></li>
47+
<li><code>squirrel.length == 2</code></li>
48+
<li><code>1 &lt;= nuts.length &lt;= 5000</code></li>
49+
<li><code>nuts[i].length == 2</code></li>
50+
<li><code>0 &lt;= tree<sub>r</sub>, squirrel<sub>r</sub>, nut<sub>i<sub>r</sub></sub> &lt;= height</code></li>
51+
<li><code>0 &lt;= tree<sub>c</sub>, squirrel<sub>c</sub>, nut<sub>i<sub>c</sub></sub> &lt;= width</code></li>
52+
</ul>
3353

3454
## 解法
3555

Binary file not shown.

solution/0600-0699/0616.Add Bold Tag in String/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
<p><strong>示例 2:</strong></p>
3232

3333
<pre>
34-
<strong>输入:</strong>s = "aaabbcc", words = ["aaa","aab","bc"]
35-
<strong>输出:</strong>"&lt;b&gt;aaabbc&lt;/b&gt;c"
34+
<strong>输入:</strong>s = "aaabbb", words = ["aa","b"]
35+
<strong>输出:</strong>"&lt;b&gt;aaabbb&lt;/b&gt;"
3636
<strong>解释:</strong>
3737
"aa"作为子字符串出现了两次: "<u>aa</u>abbb" 和 "a<u>aa</u>bbb"。
3838
"b"作为子字符串出现了三次: "aaa<u>b</u>bb"、"aaab<u>b</u>b" 和 "aaabb<u>b</u>"。

solution/0600-0699/0650.2 Keys Keyboard/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [650. 只有两个键的键盘](https://leetcode.cn/problems/2-keys-keyboard)
1+
# [650. 两个键的键盘](https://leetcode.cn/problems/2-keys-keyboard)
22

33
[English Version](/solution/0600-0699/0650.2%20Keys%20Keyboard/README_EN.md)
44

solution/0600-0699/0651.4 Keys Keyboard/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [651. 4 键键盘](https://leetcode.cn/problems/4-keys-keyboard)
1+
# [651. 四个键的键盘](https://leetcode.cn/problems/4-keys-keyboard)
22

33
[English Version](/solution/0600-0699/0651.4%20Keys%20Keyboard/README_EN.md)
44

solution/0800-0899/0819.Most Common Word/README.md

+25-22
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,42 @@
66

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

9-
<p>给定一个段落 (paragraph) 和一个禁用单词列表 (banned)。返回出现次数最多,同时不在禁用列表中的单词。</p>
9+
<p>给你一个字符串 <code>paragraph</code> 和一个表示禁用词的字符串数组 <code>banned</code> ,返回出现频率最高的非禁用词。题目数据 <strong>保证 </strong>至少存在一个非禁用词,且答案<strong> 唯一 </strong>。</p>
1010

11-
<p>题目保证至少有一个词不在禁用列表中,而且答案唯一。</p>
12-
13-
<p>禁用列表中的单词用小写字母表示,不含标点符号。段落中的单词不区分大小写。答案都是小写字母。</p>
11+
<p><code>paragraph</code> 中的单词 <strong>不区分大小写</strong> ,答案应以 <strong>小写 </strong>形式返回。</p>
1412

1513
<p>&nbsp;</p>
1614

17-
<p><strong>示例:</strong></p>
18-
19-
<pre><strong>输入:</strong>
20-
paragraph = &quot;Bob hit a ball, the hit BALL flew far after it was hit.&quot;
21-
banned = [&quot;hit&quot;]
22-
<strong>输出:</strong> &quot;ball&quot;
23-
<strong>解释:</strong>
24-
&quot;hit&quot; 出现了3次,但它是一个禁用的单词。
25-
&quot;ball&quot; 出现了2次 (同时没有其他单词出现2次),所以它是段落里出现次数最多的,且不在禁用列表中的单词。
26-
注意,所有这些单词在段落里不区分大小写,标点符号需要忽略(即使是紧挨着单词也忽略, 比如 &quot;ball,&quot;),
27-
&quot;hit&quot;不是最终的答案,虽然它出现次数更多,但它在禁用单词列表中。
15+
<p><strong class="example">示例 1:</strong></p>
16+
17+
<pre>
18+
<strong>输入:</strong>paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]
19+
<strong>输出:</strong>"ball"
20+
<strong>解释:</strong>
21+
"hit" 出现了 3 次,但它是禁用词。
22+
"ball" 出现了两次(没有其他单词出现这么多次),因此它是段落中出现频率最高的非禁用词。
23+
请注意,段落中的单词不区分大小写,
24+
标点符号会被忽略(即使它们紧挨着单词,如 "ball,"),
25+
并且尽管 "hit" 出现的次数更多,但它不能作为答案,因为它是禁用词。
26+
</pre>
27+
28+
<p><strong class="example">示例 2:</strong></p>
29+
30+
<pre>
31+
<strong>输入:</strong>paragraph = "a.", banned = []
32+
<strong>输出:</strong>"a"
2833
</pre>
2934

3035
<p>&nbsp;</p>
3136

3237
<p><strong>提示:</strong></p>
3338

3439
<ul>
35-
<li><code>1 &lt;= 段落长度 &lt;= 1000</code></li>
36-
<li><code>0 &lt;= 禁用单词个数 &lt;= 100</code></li>
37-
<li><code>1 &lt;= 禁用单词长度 &lt;= 10</code></li>
38-
<li>答案是唯一的, 且都是小写字母&nbsp;(即使在 <code>paragraph</code> 里是大写的,即使是一些特定的名词,答案都是小写的。)</li>
39-
<li><code>paragraph</code>&nbsp;只包含字母、空格和下列标点符号<code>!?&#39;,;.</code></li>
40-
<li>不存在没有连字符或者带有连字符的单词。</li>
41-
<li>单词里只包含字母,不会出现省略号或者其他标点符号。</li>
40+
<li><code>1 &lt;= paragraph.length &lt;= 1000</code></li>
41+
<li><code>paragraph</code> 由英文字母、空格 <code>' '</code>、和以下符号组成:<code>"!?',;."</code></li>
42+
<li><code>0 &lt;= banned.length &lt;= 100</code></li>
43+
<li><code>1 &lt;= banned[i].length &lt;= 10</code></li>
44+
<li><code>banned[i]</code> 仅由小写英文字母组成</li>
4245
</ul>
4346

4447
## 解法

solution/0800-0899/0864.Shortest Path to Get All Keys/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/images/lc-keys2.jpg" /></p>
3030

3131
<pre>
32-
<strong>输入:</strong>grid = ["@.a.#","###.#","b.A.B"]
32+
<strong>输入:</strong>grid = ["@.a..","###.#","b.A.B"]
3333
<strong>输出:</strong>8
3434
<strong>解释:</strong>目标是获得所有钥匙,而不是打开所有锁。
3535
</pre>

solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,45 @@
99
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>
1010

1111
<p>&nbsp;</p>
12+
1213
<p><strong class="example">Example 1:</strong></p>
1314

1415
<pre>
16+
1517
<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2
18+
1619
<strong>Output:</strong> 4
20+
1721
<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:
22+
1823
[<u><strong>1,0,1</strong></u>,0,1]
24+
1925
[<u><strong>1,0,1,0</strong></u>,1]
26+
2027
[1,<u><strong>0,1,0,1</strong></u>]
28+
2129
[1,0,<u><strong>1,0,1</strong></u>]
30+
2231
</pre>
2332

2433
<p><strong class="example">Example 2:</strong></p>
2534

2635
<pre>
36+
2737
<strong>Input:</strong> nums = [0,0,0,0,0], goal = 0
38+
2839
<strong>Output:</strong> 15
40+
2941
</pre>
3042

3143
<p>&nbsp;</p>
44+
3245
<p><strong>Constraints:</strong></p>
3346

3447
<ul>
35-
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
36-
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
37-
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
48+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
49+
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
50+
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
3851
</ul>
3952

4053
## Solutions

0 commit comments

Comments
 (0)