Skip to content

feat: update lc problems #4523

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 1 commit into from
Jun 25, 2025
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
37 changes: 24 additions & 13 deletions solution/0000-0099/0049.Group Anagrams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,41 @@ tags:

<!-- description:start -->

<p>给你一个字符串数组,请你将 <strong>字母异位词</strong> 组合在一起。可以按任意顺序返回结果列表。</p>

<p><strong>字母异位词</strong> 是由重新排列源单词的所有字母得到的一个新单词。</p>
<p>给你一个字符串数组,请你将 <span data-keyword="anagram">字母异位词</span> 组合在一起。可以按任意顺序返回结果列表。</p>

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong> strs = <code>["eat", "tea", "tan", "ate", "nat", "bat"]</code>
<strong>输出: </strong>[["bat"],["nat","tan"],["ate","eat","tea"]]</pre>
<div class="example-block">
<p><strong>输入:</strong> strs = ["eat", "tea", "tan", "ate", "nat", "bat"]</p>

<p><strong>输出: </strong>[["bat"],["nat","tan"],["ate","eat","tea"]]</p>

<p><strong>解释:</strong></p>

<ul>
<li>在 strs 中没有字符串可以通过重新排列来形成 <code>"bat"</code>。</li>
<li>字符串 <code>"nat"</code> 和 <code>"tan"</code> 是字母异位词,因为它们可以重新排列以形成彼此。</li>
<li>字符串 <code>"ate"</code>&nbsp;,<code>"eat"</code>&nbsp;和 <code>"tea"</code> 是字母异位词,因为它们可以重新排列以形成彼此。</li>
</ul>
</div>

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

<pre>
<strong>输入:</strong> strs = <code>[""]</code>
<strong>输出: </strong>[[""]]
</pre>
<div class="example-block">
<p><strong>输入:</strong> strs = [""]</p>

<p><strong>输出: </strong>[[""]]</p>
</div>

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

<pre>
<strong>输入:</strong> strs = <code>["a"]</code>
<strong>输出: </strong>[["a"]]</pre>
<div class="example-block">
<p><strong>输入:</strong> strs = ["a"]</p>

<p><strong>输出: </strong>[["a"]]</p>
</div>

<p>&nbsp;</p>

Expand Down
11 changes: 7 additions & 4 deletions solution/0000-0099/0066.Plus One/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ tags:

<!-- description:start -->

<p>给定一个由 <strong>整数 </strong>组成的<strong> 非空</strong> 数组所表示的非负整数,在该数的基础上加一。</p>
<p>给定一个表示 <strong>大整数</strong> 的整数数组 <code>digits</code>,其中 <code>digits[i]</code> 是整数的第 <code>i</code> 位数字。这些数字按从左到右,从最高位到最低位排列。这个大整数不包含任何前导 <code>0</code>。</p>

<p>最高位数字存放在数组的首位, 数组中每个元素只存储<strong>单个</strong>数字。</p>

<p>你可以假设除了整数 0 之外,这个整数不会以零开头。</p>
<p>将大整数加 1,并返回结果的数字数组。</p>

<p>&nbsp;</p>

Expand All @@ -31,6 +29,8 @@ tags:
<strong>输入:</strong>digits = [1,2,3]
<strong>输出:</strong>[1,2,4]
<strong>解释:</strong>输入数组表示数字 123。
加 1 后得到 123 + 1 = 124。
因此,结果应该是 [1,2,4]。
</pre>

<p><strong>示例&nbsp;2:</strong></p>
Expand All @@ -39,6 +39,8 @@ tags:
<strong>输入:</strong>digits = [4,3,2,1]
<strong>输出:</strong>[4,3,2,2]
<strong>解释:</strong>输入数组表示数字 4321。
加 1 后得到 4321 + 1 = 4322。
因此,结果应该是 [4,3,2,2]。
</pre>

<p><strong>示例 3:</strong></p>
Expand All @@ -58,6 +60,7 @@ tags:
<ul>
<li><code>1 &lt;= digits.length &lt;= 100</code></li>
<li><code>0 &lt;= digits[i] &lt;= 9</code></li>
<li><code>digits</code>&nbsp;不包含任何前导 <code>0</code>。</li>
</ul>

<!-- description:end -->
Expand Down
4 changes: 3 additions & 1 deletion solution/0200-0299/0228.Summary Ranges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ tags:

<p>给定一个 &nbsp;<strong>无重复元素</strong> 的&nbsp;<strong>有序</strong> 整数数组 <code>nums</code> 。</p>

<p>返回 <em><strong>恰好覆盖数组中所有数字</strong> 的 <strong>最小有序</strong> 区间范围列表&nbsp;</em>。也就是说,<code>nums</code> 的每个元素都恰好被某个区间范围所覆盖,并且不存在属于某个范围但不属于 <code>nums</code> 的数字 <code>x</code> 。</p>
<p>区间 <code>[a,b]</code> 是从 <code>a</code> 到 <code>b</code>(包含)的所有整数的集合。</p>

<p>返回 <em><strong>恰好覆盖数组中所有数字</strong> 的 <strong>最小有序</strong> 区间范围列表&nbsp;</em>。也就是说,<code>nums</code> 的每个元素都恰好被某个区间范围所覆盖,并且不存在属于某个区间但不属于 <code>nums</code> 的数字 <code>x</code> 。</p>

<p>列表中的每个区间范围 <code>[a,b]</code> 应该按如下格式输出:</p>

Expand Down
36 changes: 27 additions & 9 deletions solution/0200-0299/0250.Count Univalue Subtrees/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,42 @@ tags:

<!-- description:start -->

<p>给定一个二叉树,统计该二叉树数值相同的<span data-keyword="subtree">子树</span>个数。</p>
<p>给定一个二叉树,统计该二叉树数值相同的 <span data-keyword="subtree">子树</span> 个数。</p>

<p>同值子树是指该子树的所有节点都拥有相同的数值。</p>

<p><strong>示例:</strong></p>
<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0250.Count%20Univalue%20Subtrees/images/unival_e1.jpg" style="width: 450px; height: 258px;" />
<pre>
<strong>输入: </strong>root = [5,1,5,5,5,null,5]
<strong>输入:</strong>root = [5,1,5,5,5,null,5]
<b>输出:</b>4
</pre>

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

<strong>输出:</strong> 4
<pre>
<b>输入:</b>root = []
<b>输出:</b>0
</pre>

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

<pre>
<b>输入:</b>root = [5,5,5,5,5,null,5]
<b>输出:</b>6
</pre>

<p>&nbsp;</p>

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

<ul>
<li>树中节点的编号在 <code>[0, 1000]</code>&nbsp;范围内</li>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
</ul>

<!-- description:end -->

## 解法
Expand Down
2 changes: 1 addition & 1 deletion solution/0300-0399/0328.Odd Even Linked List/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tags:

<!-- description:start -->

<p>给定单链表的头节点&nbsp;<code>head</code>&nbsp;,将所有索引为奇数的节点和索引为偶数的节点分别组合在一起,然后返回重新排序的列表。</p>
<p>给定单链表的头节点&nbsp;<code>head</code>&nbsp;,将所有索引为奇数的节点和索引为偶数的节点分别分组,保持它们原有的相对顺序,然后把偶数索引节点分组连接到奇数索引节点分组之后,返回重新排序的链表。</p>

<p><strong>第一个</strong>节点的索引被认为是 <strong>奇数</strong> , <strong>第二个</strong>节点的索引为&nbsp;<strong>偶数</strong> ,以此类推。</p>

Expand Down
2 changes: 1 addition & 1 deletion solution/0400-0499/0412.Fizz Buzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tags:

<!-- description:start -->

<p>给你一个整数 <code>n</code> ,找出从 <code>1</code> 到 <code>n</code> 各个整数的 Fizz Buzz 表示,并用字符串数组 <code>answer</code>(<strong>下标从 1 开始</strong>)返回结果,其中:</p>
<p>给你一个整数 <code>n</code> ,返回一个字符串数组 <code>answer</code>(<strong>下标从 1 开始</strong>),其中:</p>

<ul>
<li><code>answer[i] == "FizzBuzz"</code> 如果 <code>i</code> 同时是 <code>3</code> 和 <code>5</code> 的倍数。</li>
Expand Down
6 changes: 3 additions & 3 deletions solution/0400-0499/0418.Sentence Screen Fitting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ bcd-e-
<p><strong>示例 3:</strong></p>

<pre>
<strong>输入:</strong>sentence = ["I", "had", "apple", "pie"], rows = 4, cols = 5
<strong>输入:</strong>sentence = ["i", "had", "apple", "pie"], rows = 4, cols = 5
<strong>输出:</strong>1
<strong>解释:</strong>
I-had
i-had
apple
pie-I
pie-i
had--
字符 '-' 表示屏幕上的一个空白位置。
</pre>
Expand Down
4 changes: 2 additions & 2 deletions solution/0500-0599/0520.Detect Capital/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ tags:

<ul>
<li>全部字母都是大写,比如 <code>"USA"</code> 。</li>
<li>单词中所有字母都不是大写,比如 <code>"leetcode"</code> 。</li>
<li>如果单词不只含有一个字母,只有首字母大写,&nbsp;比如&nbsp;<code>"Google"</code> 。</li>
<li>所有字母都不是大写,比如 <code>"leetcode"</code> 。</li>
<li>只有首字母大写,&nbsp;比如&nbsp;<code>"Google"</code> 。</li>
</ul>

<p>给你一个字符串 <code>word</code> 。如果大写用法正确,返回 <code>true</code> ;否则,返回 <code>false</code> 。</p>
Expand Down
4 changes: 1 addition & 3 deletions solution/0500-0599/0550.Game Play Analysis IV/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ tags:
每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0)。
</pre>

<p>&nbsp;</p>

<p>编写解决方案,报告在首次登录的第二天再次登录的玩家的 <strong>比率</strong>,<strong>四舍五入到小数点后两位</strong>。换句话说,你需要计算从首次登录日期开始至少连续两天登录的玩家的数量,然后除以玩家总数。</p>
<p>编写解决方案,报告在首次登录的第二天再次登录的玩家的 <strong>比率</strong>,<strong>四舍五入到小数点后两位</strong>。换句话说,你需要计算从首次登录后的第二天登录的玩家数量,并将其除以总玩家数。</p>

<p>结果格式如下所示:</p>

Expand Down
6 changes: 3 additions & 3 deletions solution/0500-0599/0550.Game Play Analysis IV/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ This table shows the activity of players of some games.
Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.
</pre>

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

<p>Write a&nbsp;solution&nbsp;to report the <strong>fraction</strong> of players that logged in again on the day after the day they first logged in, <strong>rounded to 2 decimal places</strong>. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.</p>
<p>Write a solution to report the <strong>fraction</strong> of players that logged in again on the day after the day they first logged in, <strong>rounded to 2 decimal places</strong>. In other words, you need to determine the number of players who logged in on the day immediately following their initial login, and divide it by the number of total players.</p>

<p>The&nbsp;result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0600-0699/0684.Redundant Connection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tags:

<p>树可以看成是一个连通且 <strong>无环&nbsp;</strong>的&nbsp;<strong>无向&nbsp;</strong>图。</p>

<p>给定往一棵&nbsp;<code>n</code> 个节点 (节点值&nbsp;<code>1~n</code>) 的树中添加一条边后的图。添加的边的两个顶点包含在 <code>1</code> 到 <code>n</code>&nbsp;中间,且这条附加的边不属于树中已存在的边。图的信息记录于长度为 <code>n</code> 的二维数组 <code>edges</code>&nbsp;,<code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>&nbsp;表示图中在 <code>ai</code> 和 <code>bi</code> 之间存在一条边。</p>
<p>给定一个图,该图从一棵&nbsp;<code>n</code> 个节点 (节点值&nbsp;<code>1~n</code>) 的树中添加一条边后获得。添加的边的两个不同顶点编号在 <code>1</code> 到 <code>n</code>&nbsp;中间,且这条附加的边不属于树中已存在的边。图的信息记录于长度为 <code>n</code> 的二维数组 <code>edges</code>&nbsp;,<code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>&nbsp;表示图中在 <code>ai</code> 和 <code>bi</code> 之间存在一条边。</p>

<p>请找出一条可以删去的边,删除后可使得剩余部分是一个有着 <code>n</code> 个节点的树。如果有多个答案,则返回数组&nbsp;<code>edges</code>&nbsp;中最后出现的那个。</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tags:
<strong>输入:</strong>nums = [1,2,1,2,6,7,5,1], k = 2
<strong>输出:</strong>[0,3,5]
<strong>解释:</strong>子数组 [1, 2], [2, 6], [7, 5] 对应的起始下标为 [0, 3, 5]。
也可以取 [2, 1], 但是结果 [1, 3, 5] 在字典序上更小
也可以取 [2, 1], 但是结果 [1, 3, 5] 在字典序上更大
</pre>

<p><strong class="example">示例 2:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tags:
<strong>Input:</strong> nums = [1,2,1,2,6,7,5,1], k = 2
<strong>Output:</strong> [0,3,5]
<strong>Explanation:</strong> Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].
We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically smaller.
We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.
</pre>

<p><strong class="example">Example 2:</strong></p>
Expand Down
12 changes: 8 additions & 4 deletions solution/0700-0799/0704.Binary Search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ tags:

<!-- description:start -->

<p>给定一个&nbsp;<code>n</code>&nbsp;个元素有序的(升序)整型数组&nbsp;<code>nums</code> 和一个目标值&nbsp;<code>target</code> &nbsp;,写一个函数搜索&nbsp;<code>nums</code>&nbsp;中的 <code>target</code>,如果目标值存在返回下标,否则返回 <code>-1</code>。</p>
<p>给定一个&nbsp;<code>n</code>&nbsp;个元素有序的(升序)整型数组&nbsp;<code>nums</code> 和一个目标值&nbsp;<code>target</code> &nbsp;,写一个函数搜索&nbsp;<code>nums</code>&nbsp;中的 <code>target</code>,如果&nbsp;<code>target</code> 存在返回下标,否则返回 <code>-1</code>。</p>

<p><br>
<p>你必须编写一个具有 <code>O(log n)</code> 时间复杂度的算法。</p>

<p><br />
<strong>示例 1:</strong></p>

<pre><strong>输入:</strong> <code>nums</code> = [-1,0,3,5,9,12], <code>target</code> = 9
<pre>
<strong>输入:</strong> <code>nums</code> = [-1,0,3,5,9,12], <code>target</code> = 9
<strong>输出:</strong> 4
<strong>解释:</strong> 9 出现在 <code>nums</code> 中并且下标为 4
</pre>

<p><strong>示例&nbsp;2:</strong></p>

<pre><strong>输入:</strong> <code>nums</code> = [-1,0,3,5,9,12], <code>target</code> = 2
<pre>
<strong>输入:</strong> <code>nums</code> = [-1,0,3,5,9,12], <code>target</code> = 2
<strong>输出:</strong> -1
<strong>解释:</strong> 2 不存在 <code>nums</code> 中因此返回 -1
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tags:

<!-- description:start -->

<p>给出一个字符串数组&nbsp;<code>words</code> 组成的一本英语词典。返回&nbsp;<code>words</code> 中最长的一个单词,该单词是由&nbsp;<code>words</code>&nbsp;词典中其他单词逐步添加一个字母组成。</p>
<p>给出一个字符串数组&nbsp;<code>words</code> 组成的一本英语词典。返回能够通过&nbsp;<code>words</code>&nbsp;中其它单词逐步添加一个字母来构造得到的&nbsp;<code>words</code> 中最长的单词。</p>

<p>若其中有多个可行的答案,则返回答案中字典序最小的单词。若无答案,则返回空字符串。</p>

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

<!-- description:start -->

<p>给你一个有&nbsp;<code>n</code>&nbsp;个节点的 <strong>有向无环图(DAG)</strong>,请你找出所有从节点 <code>0</code>&nbsp;到节点 <code>n-1</code>&nbsp;的路径并输出(<strong>不要求按特定顺序</strong>)</p>
<p>给你一个有&nbsp;<code>n</code>&nbsp;个节点的 <strong>有向无环图(DAG)</strong>,请你找出从节点 <code>0</code>&nbsp;到节点 <code>n-1</code>&nbsp;的所有路径并输出(<strong>不要求按特定顺序</strong>)</p>

<p><meta charset="UTF-8" />&nbsp;<code>graph[i]</code>&nbsp;是一个从节点 <code>i</code> 可以访问的所有节点的列表(即从节点 <code>i</code> 到节点&nbsp;<code>graph[i][j]</code>存在一条有向边)。</p>

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

<!-- description:start -->

<p>如果序列 <code>X_1, X_2, ..., X_n</code> 满足下列条件,就说它是 <em>斐波那契式 </em>的:</p>
<p>如果序列&nbsp;<code>x<sub>1</sub>, x<sub>2</sub>, ..., x<sub>2</sub></code>&nbsp;满足下列条件,就说它是&nbsp;<em>斐波那契式&nbsp;</em>的:</p>

<ul>
<li><code>n >= 3</code></li>
<li>对于所有 <code>i + 2 <= n</code>,都有 <code>X_i + X_{i+1} = X_{i+2}</code></li>
<li><code>n &gt;= 3</code></li>
<li>对于所有&nbsp;<code>i + 2 &lt;= n</code>,都有&nbsp;<code>x<sub>i</sub>&nbsp;+ x<sub>i+1</sub>&nbsp;== x<sub>i+2</sub></code></li>
</ul>

<p>给定一个<strong>严格递增</strong>的正整数数组形成序列 arr ,找到 <font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.600000381469727px"><span style="caret-color:#c7254e"><span style="background-color:#f9f2f4">arr</span></span></span></font></font> 中最长的斐波那契式的子序列的长度。如果一个不存在,返回  0 。</p>
<p>给定一个&nbsp;<strong>严格递增&nbsp;</strong>的正整数数组形成序列 <code>arr</code>&nbsp;,找到 <code><font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.600000381469727px"><span style="caret-color:#c7254e"><span style="background-color:#f9f2f4">arr</span></span></span></font></font></code>&nbsp;中最长的斐波那契式的子序列的长度。如果不存在,返回&nbsp;&nbsp;<code>0</code> 。</p>

<p><em>(回想一下,子序列是从原序列 <font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.600000381469727px"><span style="caret-color:#c7254e"><span style="background-color:#f9f2f4">arr</span></span></span></font></font> 中派生出来的,它从 <font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.600000381469727px"><span style="caret-color:#c7254e"><span style="background-color:#f9f2f4">arr</span></span></span></font></font> 中删掉任意数量的元素(也可以不删),而不改变其余元素的顺序。例如, <code>[3, 5, 8]</code> 是 <code>[3, 4, 5, 6, 7, 8]</code> 的一个子序列)</em></p>
<p><strong>子序列</strong> 是通过从另一个序列 <code>arr</code> 中删除任意数量的元素(包括删除 0 个元素)得到的,同时不改变剩余元素顺序。例如,<code>[3, 5, 8]</code><code>[3, 4, 5, 6, 7, 8]</code>&nbsp;的子序列。</p>

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

<ul>
</ul>
Expand All @@ -42,22 +42,22 @@ tags:
<strong>解释: </strong>最长的斐波那契式子序列为 [1,2,3,5,8] 。
</pre>

<p><strong>示例 2:</strong></p>
<p><strong>示例&nbsp;2:</strong></p>

<pre>
<strong>输入: </strong>arr =<strong> </strong>[1,3,7,11,12,14,18]
<strong>输出: </strong>3
<strong>解释</strong>: 最长的斐波那契式子序列有 [1,11,12]、[3,11,14] 以及 [7,11,18] 。
</pre>

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

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

<ul>
<li><code>3 <= arr.length <= 1000</code></li>
<li><code>3 &lt;= arr.length &lt;= 1000</code></li>
<li>
<p><code>1 <= arr[i] < arr[i + 1] <= 10^9</code></p>
<p><code>1 &lt;= arr[i] &lt; arr[i + 1] &lt;= 10<sup>9</sup></code></p>
</li>
</ul>

Expand Down
Loading