Skip to content

feat: update lc problems #2957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tags:

<p>&nbsp;</p>

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

<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>

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

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

<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>

Expand All @@ -54,7 +54,7 @@ tags:
<strong>输出:</strong>[[1,1],[2,1]]
</pre>

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

<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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tags:

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

<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>
<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>

<p>&nbsp;</p>

Expand Down
6 changes: 3 additions & 3 deletions solution/0200-0299/0290.Word Pattern/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ tags:

<p>&nbsp;</p>

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

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

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

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

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

<pre>
<strong>输入:</strong> pattern = <code>"aaaa"</code>, s = <code>"dog cat cat dog"</code>
Expand Down
13 changes: 4 additions & 9 deletions solution/0400-0499/0409.Longest Palindrome/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ tags:

<!-- description:start -->

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

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

<p>&nbsp;</p>

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

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

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

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

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

<pre>
<strong>输入:</strong>s = "aaaaaccc"
<strong>输出:</strong>7</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ tags:

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

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

<p> </p>
<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong>root = [4,2,5,1,3]
Expand All @@ -42,37 +42,21 @@ tags:
<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;" />
</pre>

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

<pre>
<strong>输入:</strong>root = [2,1,3]
<strong>输出:</strong>[1,2,3]
</pre>

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

<pre>
<strong>输入:</strong>root = []
<strong>输出:</strong>[]
<strong>解释:</strong>输入是空树,所以输出也是空链表。
</pre>

<p><strong>示例 4:</strong></p>

<pre>
<strong>输入:</strong>root = [1]
<strong>输出:</strong>[1]
</pre>

<p> </p>
<p>&nbsp;</p>

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

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

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ tags:

<p>&nbsp;</p>

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

<pre>
<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]
<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]
</pre>

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

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

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

<pre>
<strong>输入:</strong> root = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ tags:

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

<p> </p>
<p>&nbsp;</p>

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

<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>

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

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

<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>

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

<p> </p>
<p>&nbsp;</p>

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

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

<!-- description:end -->
Expand Down
39 changes: 7 additions & 32 deletions solution/0500-0599/0510.Inorder Successor in BST II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tags:

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

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

<pre>
class Node {
Expand All @@ -32,9 +32,9 @@ class Node {
public Node parent;
}</pre>

<p> </p>
<p>&nbsp;</p>

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

<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>

Expand All @@ -44,7 +44,7 @@ class Node {
<strong>解析:</strong>1 的中序后继结点是 2 。注意节点和返回值都是 Node 类型的。
</pre>

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

<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>

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

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

<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>

<pre>
<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
<strong>输出:</strong>17
</pre>

<p><strong>示例 4:</strong></p>

<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>

<pre>
<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
<strong>输出:</strong>15
</pre>

<p><strong>示例 5:</strong></p>

<pre>
<strong>输入:</strong>tree = [0], node = 0
<strong>输出:</strong>null
</pre>

<p> </p>
<p>&nbsp;</p>

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

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

<p> </p>
<p>&nbsp;</p>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tags:

<p>&nbsp;</p>

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

<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>

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

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

<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>

Expand Down
2 changes: 1 addition & 1 deletion solution/1300-1399/1393.Capital GainLoss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tags:
| operation_day | int |
| price | int |
+---------------+---------+
(stock_name, day) 是这张表的主键(具有唯一值的列的组合)
(stock_name, operation_day) 是这张表的主键(具有唯一值的列的组合)
operation 列使用的是一种枚举类型,包括:('Sell','Buy')
此表的每一行代表了名为 stock_name 的某支股票在 operation_day 这一天的操作价格。
此表可以保证,股票的每个“卖出”操作在前一天都有相应的“买入”操作。并且,股票的每个“买入”操作在即将到来的一天都有相应的“卖出”操作。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,54 @@ tags:

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

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

<pre>class Node {
<pre>
class Node {
public int val;
public Node left;
public Node right;
public Node parent;
}
</pre>

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

<p> </p>
<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<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;">
<pre><strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
<p><strong class="example">示例 1:</strong></p>
<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;" />
<pre>
<strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
<strong>输出:</strong> 3
<strong>解释:</strong> 节点 5 和 1 的最近公共祖先是 3。
</pre>

<p><strong>示例 2:</strong></p>
<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;">
<pre><strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
<p><strong class="example">示例 2:</strong></p>
<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;" />
<pre>
<strong>输入:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
<strong>输出:</strong> 5
<strong>解释:</strong> 节点 5 和 4 的最近公共祖先是 5,根据定义,一个节点可以是自身的最近公共祖先。
</pre>

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

<pre><strong>输入:</strong> root = [1,2], p = 1, q = 2
<pre>
<strong>输入:</strong> root = [1,2], p = 1, q = 2
<strong>输出:</strong> 1
</pre>

<p> </p>
<p>&nbsp;</p>

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

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

<!-- description:end -->
Expand Down
Loading
Loading