Skip to content

feat: add new lc problems #4634

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 3 commits into from
Aug 10, 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
4 changes: 3 additions & 1 deletion solution/0000-0099/0032.Longest Valid Parentheses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ tags:

<!-- description:start -->

<p>给你一个只包含 <code>'('</code>&nbsp;和 <code>')'</code>&nbsp;的字符串,找出最长有效(格式正确且连续)括号<span data-keyword="substring">子串</span>的长度。</p>
<p>给你一个只包含 <code>'('</code> 和 <code>')'</code> 的字符串,找出最长有效(格式正确且连续)括号 <span data-keyword="substring">子串</span> 的长度。</p>

<p>左右括号匹配,即每个左括号都有对应的右括号将其闭合的字符串是格式正确的,比如&nbsp;<code>"(()())"</code>。</p>

<p>&nbsp;</p>

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

<p>整数数组 <code>nums</code> 按升序排列,数组中的值 <strong>互不相同</strong> 。</p>

<p>在传递给函数之前,<code>nums</code> 在预先未知的某个下标 <code>k</code>(<code>0 &lt;= k &lt; nums.length</code>)上进行了 <strong>旋转</strong>,使数组变为 <code>[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]</code>(下标 <strong>从 0 开始</strong> 计数)。例如, <code>[0,1,2,4,5,6,7]</code> 在下标 <code>3</code> 处经旋转后可能变为&nbsp;<code>[4,5,6,7,0,1,2]</code> 。</p>
<p>在传递给函数之前,<code>nums</code> 在预先未知的某个下标 <code>k</code>(<code>0 &lt;= k &lt; nums.length</code>)上进行了 <strong>旋转</strong>,使数组变为 <code>[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]</code>(下标 <strong>从 0 开始</strong> 计数)。例如, <code>[0,1,2,4,5,6,7]</code> 向左旋转&nbsp;<code>3</code>&nbsp;次后可能变为&nbsp;<code>[4,5,6,7,0,1,2]</code> 。</p>

<p>给你 <strong>旋转后</strong> 的数组 <code>nums</code> 和一个整数 <code>target</code> ,如果 <code>nums</code> 中存在这个目标值 <code>target</code> ,则返回它的下标,否则返回&nbsp;<code>-1</code>&nbsp;。</p>

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

<p>There is an integer array <code>nums</code> sorted in ascending order (with <strong>distinct</strong> values).</p>

<p>Prior to being passed to your function, <code>nums</code> is <strong>possibly rotated</strong> at an unknown pivot index <code>k</code> (<code>1 &lt;= k &lt; nums.length</code>) such that the resulting array is <code>[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]</code> (<strong>0-indexed</strong>). For example, <code>[0,1,2,4,5,6,7]</code> might be rotated at pivot index <code>3</code> and become <code>[4,5,6,7,0,1,2]</code>.</p>
<p>Prior to being passed to your function, <code>nums</code> is <strong>possibly left rotated</strong> at an unknown index <code>k</code> (<code>1 &lt;= k &lt; nums.length</code>) such that the resulting array is <code>[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]</code> (<strong>0-indexed</strong>). For example, <code>[0,1,2,4,5,6,7]</code> might be left rotated by&nbsp;<code>3</code>&nbsp;indices and become <code>[4,5,6,7,0,1,2]</code>.</p>

<p>Given the array <code>nums</code> <strong>after</strong> the possible rotation and an integer <code>target</code>, return <em>the index of </em><code>target</code><em> if it is in </em><code>nums</code><em>, or </em><code>-1</code><em> if it is not in </em><code>nums</code>.</p>

Expand Down
8 changes: 4 additions & 4 deletions solution/0000-0099/0045.Jump Game II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ tags:

<p>给定一个长度为 <code>n</code> 的 <strong>0 索引</strong>整数数组 <code>nums</code>。初始位置为 <code>nums[0]</code>。</p>

<p>每个元素 <code>nums[i]</code> 表示从索引 <code>i</code> 向后跳转的最大长度。换句话说,如果你在 <code>nums[i]</code> 处,你可以跳转到任意 <code>nums[i + j]</code> 处:</p>
<p>每个元素 <code>nums[i]</code> 表示从索引 <code>i</code> 向后跳转的最大长度。换句话说,如果你在索引&nbsp;<code>i</code>&nbsp;处,你可以跳转到任意 <code>(i + j)</code> 处</p>

<ul>
<li><code>0 &lt;= j &lt;= nums[i]</code>&nbsp;</li>
<li><code>0 &lt;= j &lt;= nums[i]</code>&nbsp;</li>
<li><code>i + j &lt; n</code></li>
</ul>

<p>返回到达&nbsp;<code>nums[n - 1]</code> 的最小跳跃次数。生成的测试用例可以到达 <code>nums[n - 1]</code>。</p>
<p>返回到达&nbsp;<code>n - 1</code>&nbsp;的最小跳跃次数。测试用例保证可以到达 <code>n - 1</code>。</p>

<p>&nbsp;</p>

Expand All @@ -54,7 +54,7 @@ tags:
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 1000</code></li>
<li>题目保证可以到达&nbsp;<code>nums[n-1]</code></li>
<li>题目保证可以到达&nbsp;<code>n - 1</code></li>
</ul>

<!-- description:end -->
Expand Down
6 changes: 3 additions & 3 deletions solution/0000-0099/0045.Jump Game II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ tags:

<!-- description:start -->

<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p>
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at&nbsp;index 0.</p>

<p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[i]</code>, you can jump to any <code>nums[i + j]</code> where:</p>
<p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at index <code>i</code>, you can jump to any index <code>(i + j)</code>&nbsp;where:</p>

<ul>
<li><code>0 &lt;= j &lt;= nums[i]</code> and</li>
<li><code>i + j &lt; n</code></li>
</ul>

<p>Return <em>the minimum number of jumps to reach </em><code>nums[n - 1]</code>. The test cases are generated such that you can reach <code>nums[n - 1]</code>.</p>
<p>Return <em>the minimum number of jumps to reach index </em><code>n - 1</code>. The test cases are generated such that you can reach index&nbsp;<code>n - 1</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0190.Reverse Bits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tags:

<ul>
<li>请注意,在某些语言(如 Java)中,没有无符号整数类型。在这种情况下,输入和输出都将被指定为有符号整数类型,并且不应影响您的实现,因为无论整数是有符号的还是无符号的,其内部的二进制表示形式都是相同的。</li>
<li>在 Java 中,编译器使用<a href="https://baike.baidu.com/item/二进制补码/5295284" target="_blank">二进制补码</a>记法来表示有符号整数。因此,在 <strong>示例 2</strong>&nbsp;中,输入表示有符号整数 <code>-3</code>,输出表示有符号整数 <code>-1073741825</code>。</li>
<li>在 Java 中,编译器使用<a href="https://baike.baidu.com/item/二进制补码/5295284" target="_blank">二进制补码</a>记法来表示有符号整数。</li>
</ul>

<p>&nbsp;</p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0190.Reverse Bits/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tags:

<ul>
<li>Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer&#39;s internal binary representation is the same, whether it is signed or unsigned.</li>
<li>In Java, the compiler represents the signed integers using <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">2&#39;s complement notation</a>. Therefore, in <strong class="example">Example 2</strong>&nbsp;below, the input represents the signed integer <code>-3</code> and the output represents the signed integer <code>-1073741825</code>.</li>
<li>In Java, the compiler represents the signed integers using <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">2&#39;s complement notation</a>.</li>
</ul>

<p>&nbsp;</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags:
- 树状数组
- 线段树
- 数组
- 分治
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags:
- Binary Indexed Tree
- Segment Tree
- Array
- Divide and Conquer
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ numMatrix.sumRegion(2, 1, 4, 3); // 返回 10 (即,右侧红色矩形的和)
<li><code>m == matrix.length</code></li>
<li><code>n == matrix[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 200</code></li>
<li><code>-10<sup>5</sup> &lt;= matrix[i][j] &lt;= 10<sup>5</sup></code></li>
<li><code>-10<font size="1">00</font>&nbsp;&lt;= matrix[i][j] &lt;= 10<font size="1">00</font></code></li>
<li><code>0 &lt;= row &lt; m</code></li>
<li><code>0 &lt;= col &lt; n</code></li>
<li><code>-10<sup>5</sup> &lt;= val &lt;= 10<sup>5</sup></code></li>
<li><code>-10<font size="1">00</font>&nbsp;&lt;= val &lt;= 10<font size="1">00</font></code></li>
<li><code>0 &lt;= row1 &lt;= row2 &lt; m</code></li>
<li><code>0 &lt;= col1 &lt;= col2 &lt; n</code></li>
<li>最多调用<code>10<sup>4</sup></code> 次&nbsp;<code>sumRegion</code> 和 <code>update</code> 方法</li>
<li>最多调用<code>5000</code>&nbsp;次&nbsp;<code>sumRegion</code> 和 <code>update</code> 方法</li>
</ul>

<!-- description:end -->
Expand Down
2 changes: 2 additions & 0 deletions solution/0300-0399/0394.Decode String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ tags:

<p>此外,你可以认为原始数据不包含数字,所有的数字只表示重复的次数 <code>k</code> ,例如不会出现像&nbsp;<code>3a</code>&nbsp;或&nbsp;<code>2[4]</code>&nbsp;的输入。</p>

<p>测试用例保证输出的长度不会超过&nbsp;<code>10<sup>5</sup></code>。</p>

<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0400-0499/0475.Heaters/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tags:

<p>Given the positions of <code>houses</code> and <code>heaters</code> on a horizontal line, return <em>the minimum radius standard of heaters&nbsp;so that those heaters could cover all houses.</em></p>

<p><strong>Notice</strong> that&nbsp;all the <code>heaters</code> follow your radius standard, and the warm radius will the same.</p>
<p><strong>Notice</strong> that&nbsp;all the <code>heaters</code> follow your radius standard, and the warm radius will be the same.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
24 changes: 13 additions & 11 deletions solution/0400-0499/0499.The Maze III/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ tags:

<!-- description:start -->

<p>由空地和墙组成的迷宫中有一个<strong>球</strong>。球可以向<strong>上(u)下(d)左(l)右(r)</strong>四个方向滚动,但在遇到墙壁前不会停止滚动。当球停下时,可以选择下一个方向。迷宫中还有一个<strong>洞</strong>,当球运动经过洞时,就会掉进洞里。</p>
<p>由空地和墙组成的迷宫中有一个<strong>球</strong>。球可以向<strong>上(u)下(d)左(l)右(r)</strong>四个方向滚动,但在遇到墙壁前不会停止滚动。当球停下时,可以选择下一个方向(必须与上一个选择的方向不同)。迷宫中还有一个<strong>洞</strong>,当球运动经过洞时,就会掉进洞里。</p>

<p>给定球的<strong>起始位置,目的地</strong>和<strong>迷宫</strong>,找出让球以最短距离掉进洞里的路径。&nbsp;距离的定义是球从起始位置(不包括)到目的地(包括)经过的<strong>空地</strong>个数。通过&#39;u&#39;, &#39;d&#39;, &#39;l&#39; 和&nbsp;&#39;r&#39;输出球的移动<strong>方向</strong>。&nbsp;由于可能有多条最短路径,&nbsp;请输出<strong>字典序最小</strong>的路径<strong>。</strong>如果球无法进入洞,输出&quot;impossible&quot;。</p>
<p>给定球的<strong>起始位置,目的地</strong>和<strong>迷宫</strong>,找出让球以最短距离掉进洞里的路径。&nbsp;距离的定义是球从起始位置(不包括)到目的地(包括)经过的<strong>空地</strong>个数。通过'u', 'd', 'l' 和&nbsp;'r'输出球的移动<strong>方向</strong>。&nbsp;由于可能有多条最短路径,&nbsp;请输出<strong>字典序最小</strong>的路径<strong>。</strong>如果球无法进入洞,输出"impossible"。</p>

<p>迷宫由一个0和1的二维数组表示。 1表示墙壁,0表示空地。你可以假定迷宫的边缘都是墙壁。起始位置和目的地的坐标通过行号和列号给出。</p>

<p>&nbsp;</p>

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

<pre><strong>输入 1:</strong> 迷宫由以下二维数组表示
<pre>
<strong>输入 1:</strong> 迷宫由以下二维数组表示

0 0 0 0 0
1 1 0 0 1
Expand All @@ -44,18 +45,19 @@ tags:
<strong>输入 2:</strong> 球的初始位置 (rowBall, colBall) = (4, 3)
<strong>输入 3:</strong> 洞的位置 (rowHole, colHole) = (0, 1)

<strong>输出:</strong> &quot;lul&quot;
<strong>输出:</strong> "lul"

<strong>解析:</strong> 有两条让球进洞的最短路径。
第一条路径是 左 -&gt; 上 -&gt; 左, 记为 &quot;lul&quot;.
第二条路径是 上 -&gt; 左, 记为 &#39;ul&#39;.
两条路径都具有最短距离6, 但&#39;l&#39; &lt; &#39;u&#39;,故第一条路径字典序更小。因此输出&quot;lul&quot;
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0499.The%20Maze%20III/images/maze_2_example_1.png" style="width: 100%;">
第一条路径是 左 -&gt; 上 -&gt; 左, 记为 "lul".
第二条路径是 上 -&gt; 左, 记为 'ul'.
两条路径都具有最短距离6, 但'l' &lt; 'u',故第一条路径字典序更小。因此输出"lul"
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0499.The%20Maze%20III/images/maze_2_example_1.png" style="width: 100%;" />
</pre>

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

<pre><strong>输入 1:</strong> 迷宫由以下二维数组表示
<pre>
<strong>输入 1:</strong> 迷宫由以下二维数组表示

0 0 0 0 0
1 1 0 0 1
Expand All @@ -66,10 +68,10 @@ tags:
<strong>输入 2:</strong> 球的初始位置 (rowBall, colBall) = (4, 3)
<strong>输入 3:</strong> 洞的位置 (rowHole, colHole) = (3, 0)

<strong>输出:</strong> &quot;impossible&quot;
<strong>输出:</strong> "impossible"

<strong>示例:</strong> 球无法到达洞。
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0499.The%20Maze%20III/images/maze_2_example_2.png" style="width: 100%;">
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0499.The%20Maze%20III/images/maze_2_example_2.png" style="width: 100%;" />
</pre>

<p>&nbsp;</p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0500-0599/0544.Output Contest Matches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tags:
<p><strong>提示:</strong></p>

<ul>
<li><code>n == 2x</code>,并且 <code>x</code> 在范围 <code>[1,12]</code> 内。</li>
<li><code>n == 2<sup>x</sup></code>,并且 <code>x</code> 在范围 <code>[1, 12]</code> 内。</li>
</ul>

<!-- description:end -->
Expand Down
41 changes: 27 additions & 14 deletions solution/0800-0899/0808.Soup Servings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,36 @@ tags:

<!-- description:start -->

<p>有&nbsp;<strong>A&nbsp;和&nbsp;B 两种类型&nbsp;</strong>的汤。一开始每种类型的汤有&nbsp;<code>n</code>&nbsp;毫升。有四种分配操作:</p>
<p>你有两种汤,<strong>A</strong> 和 <strong>B</strong>,每种初始为 <code>n</code>&nbsp;毫升。在每一轮中,会随机选择以下四种操作中的一种,每种操作的概率为 <code>0.25</code>,且与之前的所有轮次 <strong>无关</strong>:</p>

<ol>
<li>提供 <code>100ml</code> 的 <strong>汤A</strong> 和 <code>0ml</code> 的 <strong>汤B</strong> 。</li>
<li>提供 <code>75ml</code> 的 <strong>汤A</strong> 和 <code>25ml</code> 的 <strong>汤B</strong> 。</li>
<li>提供 <code>50ml</code> 的 <strong>汤A</strong> 和 <code>50ml</code> 的 <strong>汤B</strong> 。</li>
<li>提供 <code>25ml</code> 的 <strong>汤A</strong> 和 <code>75ml</code> 的 <strong>汤B</strong> 。</li>
<li>从汤 A 取 100 毫升,从汤 B 取 0 毫升</li>
<li>从汤 A 取 75 毫升,从汤 B 取 25 毫升</li>
<li>从汤 A 取 50 毫升,从汤 B 取 50 毫升</li>
<li>从汤 A 取 25 毫升,从汤 B 取 75 毫升</li>
</ol>

<p>当我们把汤分配给某人之后,汤就没有了。每个回合,我们将从四种概率同为 <code>0.25</code> 的操作中进行分配选择。如果汤的剩余量不足以完成某次操作,我们将尽可能分配。当两种类型的汤都分配完时,停止操作。</p>
<p><strong>注意:</strong></p>

<p><strong>注意&nbsp;</strong>不存在先分配 <code>100</code> ml <strong>汤B</strong> 的操作。</p>
<ul>
<li>不存在从汤 A 取&nbsp;<code>0</code>&nbsp;ml 和从汤 B 取&nbsp;<code>100</code> ml 的操作。</li>
<li>汤 A 和 B 在每次操作中同时被取出。</li>
<li>如果一次操作要求你取出比剩余的汤更多的量,请取出该汤剩余的所有部分。</li>
</ul>

<p>操作过程在任何回合中任一汤被取完后立即停止。</p>

<p>需要返回的值:&nbsp;<strong>汤A&nbsp;</strong>先分配完的概率 +&nbsp;&nbsp;<strong>汤A和汤B&nbsp;</strong>同时分配完的概率 / 2。返回值在正确答案&nbsp;<code>10<sup>-5</sup></code>&nbsp;的范围内将被认为是正确的。</p>
<p>返回汤 A 在 B 前取完的概率,加上两种汤在 <strong>同一回合&nbsp;</strong>取完概率的一半。返回值在正确答案&nbsp;<code>10<sup>-5</sup></code>&nbsp;的范围内将被认为是正确的。</p>

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong> n = 50
<strong>输出:</strong> 0.62500
<strong>解释:</strong>如果我们选择前两个操作<strong>,</strong>A 首先将变为空。
<strong>输入:</strong>n = 50
<strong>输出:</strong>0.62500
<strong>解释:
</strong>如果我们选择前两个操作<strong>,</strong>A 首先将变为空。
对于第三个操作,A 和 B 会同时变为空。
对于第四个操作,B 首先将变为空。<strong>
</strong>所以 A 变为空的总概率加上 A 和 B 同时变为空的概率的一半是 0.25 *(1 + 1 + 0.5 + 0)= 0.625。
Expand All @@ -49,16 +56,22 @@ tags:
<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong> n = 100
<strong>输出:</strong> 0.71875
<strong>输入:</strong>n = 100
<strong>输出:</strong>0.71875
<strong>解释:</strong>
如果我们选择第一个操作,A 首先将变为空。
如果我们选择第二个操作,A 将在执行操作 [1, 2, 3] 时变为空,然后 A 和 B 在执行操作 4 时同时变空。
如果我们选择第三个操作,A 将在执行操作 [1, 2] 时变为空,然后 A 和 B 在执行操作 3 时同时变空。
如果我们选择第四个操作,A 将在执行操作 1 时变为空,然后 A 和 B 在执行操作 2 时同时变空。
所以 A 变为空的总概率加上 A 和 B 同时变为空的概率的一半是 0.71875。
</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code>​​​​​​​</li>
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>

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