Skip to content

Commit 5365e1e

Browse files
authored
feat: update lc problems (#2957)
1 parent 8c14fcb commit 5365e1e

File tree

73 files changed

+456
-256
lines changed

Some content is hidden

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

73 files changed

+456
-256
lines changed

solution/0100-0199/0138.Copy List with Random Pointer/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tags:
3636

3737
<p>&nbsp;</p>
3838

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

4141
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/images/e1.png" style="height: 142px; width: 700px;" /></p>
4242

@@ -45,7 +45,7 @@ tags:
4545
<strong>输出:</strong>[[7,null],[13,0],[11,4],[10,2],[1,0]]
4646
</pre>
4747

48-
<p><strong>示例 2:</strong></p>
48+
<p><strong class="example">示例 2:</strong></p>
4949

5050
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/images/e2.png" style="height: 114px; width: 700px;" /></p>
5151

@@ -54,7 +54,7 @@ tags:
5454
<strong>输出:</strong>[[1,1],[2,1]]
5555
</pre>
5656

57-
<p><strong>示例 3:</strong></p>
57+
<p><strong class="example">示例 3:</strong></p>
5858

5959
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/images/e3.png" style="height: 122px; width: 700px;" /></strong></p>
6060

solution/0200-0299/0209.Minimum Size Subarray Sum/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tags:
2121

2222
<p>给定一个含有&nbsp;<code>n</code><strong>&nbsp;</strong>个正整数的数组和一个正整数 <code>target</code><strong> 。</strong></p>
2323

24-
<p>找出该数组中满足其总和大于等于<strong> </strong><code>target</code><strong> </strong>的长度最小的 <strong>连续<span data-keyword="subarray-nonempty">子数组</span></strong>&nbsp;<code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> ,并返回其长度<strong>。</strong>如果不存在符合条件的子数组,返回 <code>0</code> 。</p>
24+
<p>找出该数组中满足其总和大于等于<strong> </strong><code>target</code><strong> </strong>的长度最小的 <strong><span data-keyword="subarray-nonempty">子数组</span></strong>&nbsp;<code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> ,并返回其长度<strong>。</strong>如果不存在符合条件的子数组,返回 <code>0</code> 。</p>
2525

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

solution/0200-0299/0290.Word Pattern/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ tags:
2323

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

26-
<p><strong>示例1:</strong></p>
26+
<p><strong class="example">示例1:</strong></p>
2727

2828
<pre>
2929
<strong>输入:</strong> pattern = <code>"abba"</code>, s = <code>"dog cat cat dog"</code>
3030
<strong>输出:</strong> true</pre>
3131

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

3434
<pre>
3535
<strong>输入:</strong>pattern = <code>"abba"</code>, s = <code>"dog cat cat fish"</code>
3636
<strong>输出:</strong> false</pre>
3737

38-
<p><strong>示例 3:</strong></p>
38+
<p><strong class="example">示例 3:</strong></p>
3939

4040
<pre>
4141
<strong>输入:</strong> pattern = <code>"aaaa"</code>, s = <code>"dog cat cat dog"</code>

solution/0400-0499/0409.Longest Palindrome/README.md

+4-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ tags:
1818

1919
<!-- description:start -->
2020

21-
<p>给定一个包含大写字母和小写字母的字符串<meta charset="UTF-8" />&nbsp;<code>s</code>&nbsp;,返回&nbsp;<em>通过这些字母构造成的 <strong>最长的回文串</strong></em>&nbsp;。</p>
21+
<p>给定一个包含大写字母和小写字母的字符串<meta charset="UTF-8" />&nbsp;<code>s</code>&nbsp;,返回&nbsp;<em>通过这些字母构造成的 <strong>最长的 <span data-keyword="palindrome-string">回文串</span></strong></em>&nbsp;的长度。</p>
2222

2323
<p>在构造过程中,请注意 <strong>区分大小写</strong> 。比如&nbsp;<code>"Aa"</code>&nbsp;不能当做一个回文字符串。</p>
2424

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

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

2929
<pre>
3030
<strong>输入:</strong>s = "abccccdd"
@@ -33,19 +33,14 @@ tags:
3333
我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。
3434
</pre>
3535

36-
<p><strong>示例 2:</strong></p>
36+
<p><strong class="example">示例 2:</strong></p>
3737

3838
<pre>
3939
<strong>输入:</strong>s = "a"
4040
<strong>输出:</strong>1
41+
<strong>解释:</strong>可以构造的最长回文串是"a",它的长度是 1。
4142
</pre>
4243

43-
<p><strong>示例 3:</strong></p>
44-
45-
<pre>
46-
<strong>输入:</strong>s = "aaaaaccc"
47-
<strong>输出:</strong>7</pre>
48-
4944
<p>&nbsp;</p>
5045

5146
<p><strong>提示:</strong></p>

solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README.md

+8-24
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ tags:
2626

2727
<p>对于双向循环列表,你可以将左右孩子指针作为双向循环链表的前驱和后继指针,第一个节点的前驱是最后一个节点,最后一个节点的后继是第一个节点。</p>
2828

29-
<p>特别地,我们希望可以 <strong>就地</strong> 完成转换操作。当转化完成以后,树中节点的左指针需要指向前驱,树中节点的右指针需要指向后继。还需要返回链表中最小元素的指针。</p>
29+
<p>特别地,我们希望可以 <strong>原地</strong> 完成转换操作。当转化完成以后,树中节点的左指针需要指向前驱,树中节点的右指针需要指向后继。还需要返回链表中最小元素的指针。</p>
3030

31-
<p> </p>
31+
<p>&nbsp;</p>
3232

33-
<p><strong>示例 1:</strong></p>
33+
<p><strong class="example">示例 1:</strong></p>
3434

3535
<pre>
3636
<strong>输入:</strong>root = [4,2,5,1,3]
@@ -42,37 +42,21 @@ tags:
4242
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/images/bstdllreturnbst.png" style="width: 400px;" />
4343
</pre>
4444

45-
<p><strong>示例 2:</strong></p>
45+
<p><strong class="example">示例 2:</strong></p>
4646

4747
<pre>
4848
<strong>输入:</strong>root = [2,1,3]
4949
<strong>输出:</strong>[1,2,3]
5050
</pre>
5151

52-
<p><strong>示例 3:</strong></p>
53-
54-
<pre>
55-
<strong>输入:</strong>root = []
56-
<strong>输出:</strong>[]
57-
<strong>解释:</strong>输入是空树,所以输出也是空链表。
58-
</pre>
59-
60-
<p><strong>示例 4:</strong></p>
61-
62-
<pre>
63-
<strong>输入:</strong>root = [1]
64-
<strong>输出:</strong>[1]
65-
</pre>
66-
67-
<p> </p>
52+
<p>&nbsp;</p>
6853

6954
<p><strong>提示:</strong></p>
7055

7156
<ul>
72-
<li><code>-1000 <= Node.val <= 1000</code></li>
73-
<li><code>Node.left.val < Node.val < Node.right.val</code></li>
74-
<li><code>Node.val</code> 的所有值都是独一无二的</li>
75-
<li><code>0 <= Number of Nodes <= 2000</code></li>
57+
<li>树中节点的数量在范围&nbsp;<code>[0, 2000]</code>&nbsp;中</li>
58+
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
59+
<li>树中的所有值都是 <strong>独一无二</strong> 的</li>
7660
</ul>
7761

7862
<!-- description:end -->

solution/0400-0499/0428.Serialize and Deserialize N-ary Tree/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ tags:
4343

4444
<p>&nbsp;</p>
4545

46-
<p><strong>示例 1:</strong></p>
46+
<p><strong class="example">示例 1:</strong></p>
4747

4848
<pre>
4949
<strong>输入:</strong> root = [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]
5050
<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]
5151
</pre>
5252

53-
<p><strong>示例 2:</strong></p>
53+
<p><strong class="example">示例 2:</strong></p>
5454

5555
<pre>
5656
<strong>输入:</strong> root = [1,null,3,2,4,null,5,6]
5757
<strong>输出:</strong> [1,null,3,2,4,null,5,6]
5858
</pre>
5959

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

6262
<pre>
6363
<strong>输入:</strong> root = []

solution/0400-0499/0429.N-ary Tree Level Order Traversal/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ tags:
2121

2222
<p>树的序列化输入是用层序遍历,每组子节点都由 null 值分隔(参见示例)。</p>
2323

24-
<p> </p>
24+
<p>&nbsp;</p>
2525

26-
<p><strong>示例 1:</strong></p>
26+
<p><strong class="example">示例 1:</strong></p>
2727

2828
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/images/narytreeexample.png" style="width: 100%; max-width: 300px;" /></p>
2929

@@ -32,7 +32,7 @@ tags:
3232
<strong>输出:</strong>[[1],[3,2,4],[5,6]]
3333
</pre>
3434

35-
<p><strong>示例 2:</strong></p>
35+
<p><strong class="example">示例 2:</strong></p>
3636

3737
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/images/sample_4_964.png" style="width: 296px; height: 241px;" /></p>
3838

@@ -41,13 +41,13 @@ tags:
4141
<strong>输出:</strong>[[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]
4242
</pre>
4343

44-
<p> </p>
44+
<p>&nbsp;</p>
4545

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

4848
<ul>
49-
<li>树的高度不会超过 <code>1000</code></li>
50-
<li>树的节点总数在 <code>[0, 10^4]</code> 之间</li>
49+
<li>树的高度不会超过&nbsp;<code>1000</code></li>
50+
<li>树的节点总数在 <code>[0,&nbsp;10<sup>4</sup>]</code> 之间</li>
5151
</ul>
5252

5353
<!-- description:end -->

solution/0500-0599/0510.Inorder Successor in BST II/README.md

+7-32
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tags:
2222

2323
<p>一个节点 <code>node</code> 的中序后继是键值比 <code>node.val</code> 大所有的节点中键值最小的那个。</p>
2424

25-
<p>你可以直接访问结点,但无法直接访问树。每个节点都会有其父节点的引用。节点 <code>Node</code> 定义如下:</p>
25+
<p>你可以直接访问结点,但无法直接访问树。每个节点都会有其父节点的引用。节点&nbsp;<code>Node</code> 定义如下:</p>
2626

2727
<pre>
2828
class Node {
@@ -32,9 +32,9 @@ class Node {
3232
public Node parent;
3333
}</pre>
3434

35-
<p> </p>
35+
<p>&nbsp;</p>
3636

37-
<p><strong>示例 1:</strong></p>
37+
<p><strong class="example">示例 1:</strong></p>
3838

3939
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/images/285_example_1.png" style="height: 117px; width: 122px;" /></p>
4040

@@ -44,7 +44,7 @@ class Node {
4444
<strong>解析:</strong>1 的中序后继结点是 2 。注意节点和返回值都是 Node 类型的。
4545
</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/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/images/285_example_2.png" style="height: 229px; width: 246px;" /></p>
5050

@@ -54,42 +54,17 @@ class Node {
5454
<strong>解析:</strong>该结点没有中序后继,因此返回<code> null 。</code>
5555
</pre>
5656

57-
<p><strong>示例 3:</strong></p>
58-
59-
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/images/285_example_34.png" style="height: 335px; width: 438px;" /></p>
60-
61-
<pre>
62-
<strong>输入:</strong>tree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 15
63-
<strong>输出:</strong>17
64-
</pre>
65-
66-
<p><strong>示例 4:</strong></p>
67-
68-
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/images/285_example_34.png" style="height: 335px; width: 438px;" /></p>
69-
70-
<pre>
71-
<strong>输入:</strong>tree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 13
72-
<strong>输出:</strong>15
73-
</pre>
74-
75-
<p><strong>示例 5:</strong></p>
76-
77-
<pre>
78-
<strong>输入:</strong>tree = [0], node = 0
79-
<strong>输出:</strong>null
80-
</pre>
81-
82-
<p> </p>
57+
<p>&nbsp;</p>
8358

8459
<p><strong>提示:</strong></p>
8560

8661
<ul>
8762
<li>树中节点的数目在范围 <code>[1, 10<sup>4</sup>]</code> 内。</li>
88-
<li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li>
63+
<li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
8964
<li>树中各结点的值均保证唯一。</li>
9065
</ul>
9166

92-
<p> </p>
67+
<p>&nbsp;</p>
9368

9469
<p><strong>进阶:</strong>你能否在不访问任何结点的值的情况下解决问题?</p>
9570

solution/0500-0599/0590.N-ary Tree Postorder Traversal/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tags:
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/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/images/narytreeexample.png" style="height: 193px; width: 300px;" /></p>
3030

@@ -33,7 +33,7 @@ tags:
3333
<strong>输出:</strong>[5,6,3,2,4,1]
3434
</pre>
3535

36-
<p><strong>示例 2:</strong></p>
36+
<p><strong class="example">示例 2:</strong></p>
3737

3838
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/images/sample_4_964.png" style="height: 269px; width: 296px;" /></p>
3939

solution/1300-1399/1393.Capital GainLoss/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tags:
2727
| operation_day | int |
2828
| price | int |
2929
+---------------+---------+
30-
(stock_name, day) 是这张表的主键(具有唯一值的列的组合)
30+
(stock_name, operation_day) 是这张表的主键(具有唯一值的列的组合)
3131
operation 列使用的是一种枚举类型,包括:('Sell','Buy')
3232
此表的每一行代表了名为 stock_name 的某支股票在 operation_day 这一天的操作价格。
3333
此表可以保证,股票的每个“卖出”操作在前一天都有相应的“买入”操作。并且,股票的每个“买入”操作在即将到来的一天都有相应的“卖出”操作。

solution/1600-1699/1650.Lowest Common Ancestor of a Binary Tree III/README.md

+20-16
Original file line numberDiff line numberDiff line change
@@ -21,50 +21,54 @@ tags:
2121

2222
<p>给定一棵二叉树中的两个节点 <code>p</code> 和 <code>q</code>,返回它们的最近公共祖先节点(LCA)。</p>
2323

24-
<p>每个节点都包含其父节点的引用(指针)。<code>Node</code> 的定义如下:</p>
24+
<p>每个节点都包含其父节点的引用(指针)。<code>Node</code>&nbsp;的定义如下:</p>
2525

26-
<pre>class Node {
26+
<pre>
27+
class Node {
2728
public int val;
2829
public Node left;
2930
public Node right;
3031
public Node parent;
3132
}
3233
</pre>
3334

34-
<p>根据<a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor">维基百科中对最近公共祖先节点的定义</a>:“两个节点 p 和 q 在二叉树 T 中的最近公共祖先节点是后代节点中既包括 p 又包括 q 的最深节点(我们允许<strong>一个节点为自身的一个后代节点</strong>)”。一个节点 x 的后代节点是节点 x 到某一叶节点间的路径中的节点 y。</p>
35+
<p>根据<a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor">维基百科中对最近公共祖先节点的定义</a>:“两个节点 p 和 q 在二叉树 T 中的最近公共祖先节点是后代节点中既包括 p&nbsp;又包括&nbsp;q&nbsp;的最深节点(我们允许<strong>一个节点为自身的一个后代节点</strong>)”。一个节点 x&nbsp;的后代节点是节点&nbsp;x 到某一叶节点间的路径中的节点 y。</p>
3536

36-
<p> </p>
37+
<p>&nbsp;</p>
3738

38-
<p><strong>示例 1:</strong></p>
39-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/images/binarytree.png" style="width: 200px; height: 190px;">
40-
<pre><strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
39+
<p><strong class="example">示例 1:</strong></p>
40+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/images/binarytree.png" style="width: 200px; height: 190px;" />
41+
<pre>
42+
<strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
4143
<strong>输出:</strong> 3
4244
<strong>解释:</strong> 节点 5 和 1 的最近公共祖先是 3。
4345
</pre>
4446

45-
<p><strong>示例 2:</strong></p>
46-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/images/binarytree.png" style="width: 200px; height: 190px;">
47-
<pre><strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
47+
<p><strong class="example">示例 2:</strong></p>
48+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/images/binarytree.png" style="width: 200px; height: 190px;" />
49+
<pre>
50+
<strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
4851
<strong>输出:</strong> 5
4952
<strong>解释:</strong> 节点 5 和 4 的最近公共祖先是 5,根据定义,一个节点可以是自身的最近公共祖先。
5053
</pre>
5154

52-
<p><strong>示例 3:</strong></p>
55+
<p><strong class="example">示例 3:</strong></p>
5356

54-
<pre><strong>输入:</strong> root = [1,2], p = 1, q = 2
57+
<pre>
58+
<strong>输入:</strong> root = [1,2], p = 1, q = 2
5559
<strong>输出:</strong> 1
5660
</pre>
5761

58-
<p> </p>
62+
<p>&nbsp;</p>
5963

6064
<p><strong>提示:</strong></p>
6165

6266
<ul>
63-
<li>树中节点个数的范围是 <code>[2, 10<sup>5</sup>]</code>。</li>
67+
<li>树中节点个数的范围是&nbsp;<code>[2, 10<sup>5</sup>]</code>。</li>
6468
<li><code>-10<sup>9</sup> &lt;= Node.val &lt;= 10<sup>9</sup></code></li>
65-
<li>所有的 <code>Node.val</code> 都是<strong>互不相同</strong>的。</li>
69+
<li>所有的&nbsp;<code>Node.val</code>&nbsp;都是<strong>互不相同</strong>的。</li>
6670
<li><code>p != q</code></li>
67-
<li><code>p</code> 和 <code>q</code> 存在于树中。</li>
71+
<li><code>p</code>&nbsp;和&nbsp;<code>q</code>&nbsp;存在于树中。</li>
6872
</ul>
6973

7074
<!-- description:end -->

0 commit comments

Comments
 (0)