Skip to content

chore: update lc problems #2164

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
Dec 28, 2023
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 @@ -15,21 +15,21 @@
<p>你所设计的解决方案必须只使用常量级的额外空间。</p>
&nbsp;

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

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

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

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

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

<pre>
<strong>输入:</strong>numbers = [<strong><em>-1</em></strong>,<strong><em>0</em></strong>], target = -1
Expand Down
15 changes: 15 additions & 0 deletions solution/0100-0199/0195.Tenth Line/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,41 @@
<p>Assume that <code>file.txt</code> has the following content:</p>

<pre>

Line 1

Line 2

Line 3

Line 4

Line 5

Line 6

Line 7

Line 8

Line 9

Line 10

</pre>

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

<pre>

Line 10

</pre>

<div class="spoilers"><b>Note:</b><br />

1. If the file contains less than 10 lines, what should you output?<br />

2. There&#39;s at least three different solutions. Try to explore all possibilities.</div>

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

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

Expand Down
37 changes: 27 additions & 10 deletions solution/0200-0299/0266.Palindrome Permutation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,39 @@

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

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

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

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

<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>s = "code"
<strong>输出:</strong>false
</pre>

<pre><strong>输入:</strong> <code>&quot;aab&quot;</code>
<strong>输出:</strong> true</pre>
<p><strong class="example">示例 2:</strong></p>

<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>s = "aab"
<strong>输出:</strong>true
</pre>

<pre><strong>输入:</strong> <code>&quot;carerac&quot;</code>
<strong>输出:</strong> true</pre>
<p><strong class="example">示例 3:</strong></p>

<pre>
<strong>输入:</strong>s = "carerac"
<strong>输出:</strong>true
</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= s.length &lt;= 5000</code></li>
<li><code>s</code> 仅由小写英文字母组成</li>
</ul>

## 解法

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

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

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

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

<p><strong>示例 1:</strong></p>
<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;" />
Expand Down Expand Up @@ -42,13 +42,13 @@
<strong>输出:</strong>[1,2]
</pre>

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

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

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

## 解法
Expand Down
2 changes: 1 addition & 1 deletion solution/0300-0399/0339.Nested List Weight Sum/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [339. 嵌套列表权重和](https://leetcode.cn/problems/nested-list-weight-sum)
# [339. 嵌套列表加权和](https://leetcode.cn/problems/nested-list-weight-sum)

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
<ul>
<li><code>1 &lt;= nums1.length, nums2.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> &lt;= nums1[i], nums2[i] &lt;= 10<sup>9</sup></code></li>
<li><code>nums1</code> 和 <code>nums2</code> 均为升序排列</li>
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
<li><code>nums1</code> 和 <code>nums2</code> 均为 <strong>升序排列</strong></li>
<li><meta charset="UTF-8" /><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
<li><code>k &lt;=&nbsp;nums1.length *&nbsp;nums2.length</code></li>
</ul>

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

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

Expand Down
62 changes: 41 additions & 21 deletions solution/0500-0599/0573.Squirrel Simulation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,50 @@

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

<p>现在有一棵树,一只松鼠和一些坚果。位置由二维网格的单元格表示。你的目标是找到松鼠收集所有坚果的<strong>最小路程</strong>,且坚果是一颗接一颗地被放在树下。松鼠一次最多只能携带<strong>一颗</strong>坚果,松鼠可以向上,向下,向左和向右四个方向移动到相邻的单元格。移动次数表示路程。</p>

<p><strong>输入 1:</strong></p>

<pre><strong>输入:</strong>
高度 : 5
宽度 : 7
树的位置 : [2,2]
松鼠 : [4,4]
坚果 : [[3,0], [2,5]]
<strong>输出:</strong> 12
<strong>解释:</strong>
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0573.Squirrel%20Simulation/images/squirrel_simulation.png" style="width: 40%;">​​​​​
<p>给你两个整数 <code>height</code> 和 <code>width</code> ,代表一个大小为 <code>height x width</code> 的花园。你还得到了以下信息:</p>

<ul>
<li>一个数组 <code>tree</code> ,其中 <code>tree = [tree<sub>r</sub>, tree<sub>c</sub>]</code> 是花园中树的位置,</li>
<li>一个数组 <code>squirrel</code> ,其中 <code>squirrel = [squirrel<sub>r</sub>, squirrel<sub>c</sub>]</code> 是花园中松鼠的位置,</li>
<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>
</ul>

<p>松鼠一次最多只能携带一个坚果,并且能够向上、下、左、右四个方向移动到相邻的单元格。</p>

<p>返回松鼠收集所有坚果并逐一放在树下的 <strong>最小距离</strong> 。</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/0500-0599/0573.Squirrel%20Simulation/images/squirrel1-grid.jpg" style="width: 573px; height: 413px;" />
<pre>
<strong>输入:</strong>height = 5, width = 7, tree = [2,2], squirrel = [4,4], nuts = [[3,0], [2,5]]
<strong>输出:</strong>12
<strong>解释:</strong>为实现最小的距离,松鼠应该先摘 [2, 5] 位置的坚果。
</pre>

<p><strong class="example">示例 2:</strong></p>
<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;" />
<pre>
<strong>输入:</strong>height = 1, width = 3, tree = [0,1], squirrel = [0,0], nuts = [[0,2]]
<strong>输出:</strong>3
</pre>

<p><strong>注意:</strong></p>
<p>&nbsp;</p>

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

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

## 解法

Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions solution/0600-0699/0616.Add Bold Tag in String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong>s = "aaabbcc", words = ["aaa","aab","bc"]
<strong>输出:</strong>"&lt;b&gt;aaabbc&lt;/b&gt;c"
<strong>输入:</strong>s = "aaabbb", words = ["aa","b"]
<strong>输出:</strong>"&lt;b&gt;aaabbb&lt;/b&gt;"
<strong>解释:</strong>
"aa"作为子字符串出现了两次: "<u>aa</u>abbb" 和 "a<u>aa</u>bbb"。
"b"作为子字符串出现了三次: "aaa<u>b</u>bb"、"aaab<u>b</u>b" 和 "aaabb<u>b</u>"。
Expand Down
2 changes: 1 addition & 1 deletion solution/0600-0699/0650.2 Keys Keyboard/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [650. 只有两个键的键盘](https://leetcode.cn/problems/2-keys-keyboard)
# [650. 两个键的键盘](https://leetcode.cn/problems/2-keys-keyboard)

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

Expand Down
2 changes: 1 addition & 1 deletion solution/0600-0699/0651.4 Keys Keyboard/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [651. 4 键键盘](https://leetcode.cn/problems/4-keys-keyboard)
# [651. 四个键的键盘](https://leetcode.cn/problems/4-keys-keyboard)

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

Expand Down
47 changes: 25 additions & 22 deletions solution/0800-0899/0819.Most Common Word/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,42 @@

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

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

<p>题目保证至少有一个词不在禁用列表中,而且答案唯一。</p>

<p>禁用列表中的单词用小写字母表示,不含标点符号。段落中的单词不区分大小写。答案都是小写字母。</p>
<p><code>paragraph</code> 中的单词 <strong>不区分大小写</strong> ,答案应以 <strong>小写 </strong>形式返回。</p>

<p>&nbsp;</p>

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

<pre><strong>输入:</strong>
paragraph = &quot;Bob hit a ball, the hit BALL flew far after it was hit.&quot;
banned = [&quot;hit&quot;]
<strong>输出:</strong> &quot;ball&quot;
<strong>解释:</strong>
&quot;hit&quot; 出现了3次,但它是一个禁用的单词。
&quot;ball&quot; 出现了2次 (同时没有其他单词出现2次),所以它是段落里出现次数最多的,且不在禁用列表中的单词。
注意,所有这些单词在段落里不区分大小写,标点符号需要忽略(即使是紧挨着单词也忽略, 比如 &quot;ball,&quot;),
&quot;hit&quot;不是最终的答案,虽然它出现次数更多,但它在禁用单词列表中。
<p><strong class="example">示例 1:</strong></p>

<pre>
<strong>输入:</strong>paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]
<strong>输出:</strong>"ball"
<strong>解释:</strong>
"hit" 出现了 3 次,但它是禁用词。
"ball" 出现了两次(没有其他单词出现这么多次),因此它是段落中出现频率最高的非禁用词。
请注意,段落中的单词不区分大小写,
标点符号会被忽略(即使它们紧挨着单词,如 "ball,"),
并且尽管 "hit" 出现的次数更多,但它不能作为答案,因为它是禁用词。
</pre>

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

<pre>
<strong>输入:</strong>paragraph = "a.", banned = []
<strong>输出:</strong>"a"
</pre>

<p>&nbsp;</p>

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

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

## 解法
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<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>

<pre>
<strong>输入:</strong>grid = ["@.a.#","###.#","b.A.B"]
<strong>输入:</strong>grid = ["@.a..","###.#","b.A.B"]
<strong>输出:</strong>8
<strong>解释:</strong>目标是获得所有钥匙,而不是打开所有锁。
</pre>
Expand Down
19 changes: 16 additions & 3 deletions solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,45 @@
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>

<p>&nbsp;</p>

<p><strong class="example">Example 1:</strong></p>

<pre>

<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2

<strong>Output:</strong> 4

<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:

[<u><strong>1,0,1</strong></u>,0,1]

[<u><strong>1,0,1,0</strong></u>,1]

[1,<u><strong>0,1,0,1</strong></u>]

[1,0,<u><strong>1,0,1</strong></u>]

</pre>

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

<pre>

<strong>Input:</strong> nums = [0,0,0,0,0], goal = 0

<strong>Output:</strong> 15

</pre>

<p>&nbsp;</p>

<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
</ul>

## Solutions
Expand Down
Loading