Skip to content

Commit c2e8a53

Browse files
authored
feat: update lc problems (#3076)
1 parent 39a5f58 commit c2e8a53

File tree

11 files changed

+81
-71
lines changed

11 files changed

+81
-71
lines changed

lcof2/剑指 Offer II 052. 展平二叉搜索树/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class Solution {
357357
var tail: TreeNode? = nil
358358
var stack = [TreeNode]()
359359
var cur = root
360-
360+
361361
while !stack.isEmpty || cur != nil {
362362
while cur != nil {
363363
stack.append(cur!)

solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ tags:
5656
<p><strong>进阶:</strong></p>
5757

5858
<ul>
59-
<li>这是 <a href="https://leetcode.cn/problems/search-in-rotated-sorted-array/description/">搜索旋转排序数组</a>&nbsp;的延伸题目,本题中的&nbsp;<code>nums</code>&nbsp; 可能包含重复元素。</li>
60-
<li>这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?</li>
59+
<li>此题与&nbsp;<a href="https://leetcode.cn/problems/search-in-rotated-sorted-array/description/">搜索旋转排序数组</a>&nbsp;相似,但本题中的&nbsp;<code>nums</code>&nbsp; 可能包含 <strong>重复</strong> 元素。这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?</li>
6160
</ul>
6261

6362
<p>&nbsp;</p>

solution/0200-0299/0249.Group Shifted Strings/README.md

+39-14
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,50 @@ tags:
1818

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

21-
<p>给定一个字符串,对该字符串可以进行 &ldquo;移位&rdquo; 的操作,也就是将字符串中每个字母都变为其在字母表中后续的字母,比如:<code>&quot;abc&quot; -&gt; &quot;bcd&quot;</code>。这样,我们可以持续进行 &ldquo;移位&rdquo; 操作,从而生成如下移位序列:</p>
21+
<p>对字符串进行 “移位” 的操作:</p>
2222

23-
<pre>&quot;abc&quot; -&gt; &quot;bcd&quot; -&gt; ... -&gt; &quot;xyz&quot;</pre>
23+
<ul>
24+
<li><strong>右移</strong>:将字符串中每个字母都变为其在字母表中 <strong>后续</strong> 的字母,其中用 'a' 替换 'z'。比如,<code>"abc"</code>&nbsp;能够右移为&nbsp;<code>"bcd"</code>,<code>"xyz"</code>&nbsp;能够右移为&nbsp;<code>"yza"</code>。</li>
25+
<li><strong>左移</strong>:将字符串中每个字母都变为其在字母表中 <b>之前</b>&nbsp;的字母,其中用 'z' 替换 'a'。比如,<code>"bcd"</code>&nbsp;能够右移为&nbsp;<code>"abc"</code>,<code>"yza"</code>&nbsp;能够右移为&nbsp;<code>"xyz"</code>。</li>
26+
</ul>
2427

25-
<p>给定一个包含仅小写字母字符串的列表,将该列表中所有满足&nbsp;&ldquo;移位&rdquo; 操作规律的组合进行分组并返回。</p>
28+
<p>我们可以不断地向两个方向移动字符串,形成 <strong>无限的移位序列</strong>。</p>
29+
30+
<ul>
31+
<li>例如,移动&nbsp;<code>"abc"</code>&nbsp;来形成序列:<code>... &lt;-&gt; "abc" &lt;-&gt; "bcd" &lt;-&gt; ... &lt;-&gt; "xyz" &lt;-&gt; "yza" &lt;-&gt; ... &lt;-&gt; "zab" &lt;-&gt; "abc" &lt;-&gt; ...</code></li>
32+
</ul>
33+
34+
<p>给定一个字符串数组&nbsp;<code>strings</code>,将属于相同移位序列的所有&nbsp;<code>strings[i]</code>&nbsp;进行分组。你可以以 <strong>任意顺序</strong> 返回答案。</p>
35+
36+
<p>&nbsp;</p>
37+
38+
<p><strong class="example">示例 1:</strong></p>
39+
40+
<div class="example-block">
41+
<p><strong>输入:</strong><span class="example-io">strings = ["abc","bcd","acef","xyz","az","ba","a","z"]</span></p>
42+
43+
<p><strong>输出:</strong><span class="example-io">[["acef"],["a","z"],["abc","bcd","xyz"],["az","ba"]]</span></p>
2644

2745
<p>&nbsp;</p>
46+
</div>
47+
48+
<p><strong class="example">示例 2:</strong></p>
49+
50+
<div class="example-block">
51+
<p><strong>输入:</strong><span class="example-io">strings = ["a"]</span></p>
52+
53+
<p><strong>输出:</strong><span class="example-io">[["a"]]</span></p>
54+
55+
<p>&nbsp;</p>
56+
</div>
57+
58+
<p><strong>提示:</strong></p>
2859

29-
<p><strong>示例:</strong></p>
30-
31-
<pre><strong>输入:</strong><code>[&quot;abc&quot;, &quot;bcd&quot;, &quot;acef&quot;, &quot;xyz&quot;, &quot;az&quot;, &quot;ba&quot;, &quot;a&quot;, &quot;z&quot;]</code>
32-
<strong>输出:</strong>
33-
[
34-
[&quot;abc&quot;,&quot;bcd&quot;,&quot;xyz&quot;],
35-
[&quot;az&quot;,&quot;ba&quot;],
36-
[&quot;acef&quot;],
37-
[&quot;a&quot;,&quot;z&quot;]
38-
]
39-
<strong>解释:</strong>可以认为字母表首尾相接,所以 &#39;z&#39; 的后续为 &#39;a&#39;,所以 [&quot;az&quot;,&quot;ba&quot;] 也满足 &ldquo;移位&rdquo; 操作规律。</pre>
60+
<ul>
61+
<li><code>1 &lt;= strings.length &lt;= 200</code></li>
62+
<li><code>1 &lt;= strings[i].length &lt;= 50</code></li>
63+
<li><code>strings[i]</code>&nbsp;只包含小写英文字母。</li>
64+
</ul>
4065

4166
<!-- description:end -->
4267

solution/0600-0699/0648.Replace Words/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ tags:
1919

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

22-
<p>在英语中,我们有一个叫做&nbsp;<strong>词根</strong>(root) 的概念,可以词根&nbsp;<strong>后面&nbsp;</strong>添加其他一些词组成另一个较长的单词——我们称这个词为 <strong>继承词</strong>&nbsp;(successor)。例如,词根&nbsp;<code>help</code>,跟随着 <strong>继承</strong>词&nbsp;<code>"ful"</code>,可以形成新的单词&nbsp;<code>"helpful"</code>。</p>
22+
<p>在英语中,我们有一个叫做&nbsp;<strong>词根</strong>(root) 的概念,可以词根&nbsp;<strong>后面&nbsp;</strong>添加其他一些词组成另一个较长的单词——我们称这个词为 <strong>衍生词</strong>&nbsp;(<strong>derivative</strong>)。例如,词根&nbsp;<code>help</code>,跟随着 <strong>继承</strong>词&nbsp;<code>"ful"</code>,可以形成新的单词&nbsp;<code>"helpful"</code>。</p>
2323

24-
<p>现在,给定一个由许多&nbsp;<strong>词根&nbsp;</strong>组成的词典 <code>dictionary</code> 和一个用空格分隔单词形成的句子 <code>sentence</code>。你需要将句子中的所有&nbsp;<strong>继承词&nbsp;</strong>用&nbsp;<strong>词根&nbsp;</strong>替换掉。如果&nbsp;<strong>继承词&nbsp;</strong>有许多可以形成它的&nbsp;<strong>词根</strong>,则用&nbsp;<strong>最短&nbsp;</strong>的 <strong>词根</strong> 替换它。</p>
24+
<p>现在,给定一个由许多&nbsp;<strong>词根&nbsp;</strong>组成的词典 <code>dictionary</code> 和一个用空格分隔单词形成的句子 <code>sentence</code>。你需要将句子中的所有&nbsp;<strong>衍生词&nbsp;</strong>用&nbsp;<strong>词根&nbsp;</strong>替换掉。如果&nbsp;<strong>衍生词&nbsp;</strong>有许多可以形成它的&nbsp;<strong>词根</strong>,则用&nbsp;<strong>最短&nbsp;</strong>的 <strong>词根</strong> 替换它。</p>
2525

2626
<p>你需要输出替换之后的句子。</p>
2727

solution/0600-0699/0648.Replace Words/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ tags:
1919

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

22-
<p>In English, we have a concept called <strong>root</strong>, which can be followed by some other word to form another longer word - let&#39;s call this word <strong>successor</strong>. For example, when the <strong>root</strong> <code>&quot;help&quot;</code> is followed by the <strong>successor</strong> word <code>&quot;ful&quot;</code>, we can form a new word <code>&quot;helpful&quot;</code>.</p>
22+
<p>In English, we have a concept called <strong>root</strong>, which can be followed by some other word to form another longer word - let&#39;s call this word <strong>derivative</strong>. For example, when the <strong>root</strong> <code>&quot;help&quot;</code> is followed by the word <code>&quot;ful&quot;</code>, we can form a derivative <code>&quot;helpful&quot;</code>.</p>
2323

24-
<p>Given a <code>dictionary</code> consisting of many <strong>roots</strong> and a <code>sentence</code> consisting of words separated by spaces, replace all the <strong>successors</strong> in the sentence with the <strong>root</strong> forming it. If a <strong>successor</strong> can be replaced by more than one <strong>root</strong>, replace it with the <strong>root</strong> that has <strong>the shortest length</strong>.</p>
24+
<p>Given a <code>dictionary</code> consisting of many <strong>roots</strong> and a <code>sentence</code> consisting of words separated by spaces, replace all the derivatives in the sentence with the <strong>root</strong> forming it. If a derivative can be replaced by more than one <strong>root</strong>, replace it with the <strong>root</strong> that has <strong>the shortest length</strong>.</p>
2525

2626
<p>Return <em>the <code>sentence</code></em> after the replacement.</p>
2727

solution/0800-0899/0852.Peak Index in a Mountain Array/README.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,9 @@ tags:
1717

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

20-
符合下列属性的数组 <code>arr</code> 称为 <strong>山脉数组</strong>
20+
<p>给定一个长度为&nbsp;<code>n</code>&nbsp;的整数 <strong>山脉&nbsp;</strong>数组&nbsp;<code>arr</code>&nbsp;,其中的值递增到一个&nbsp;<strong>峰值元素</strong>&nbsp;然后递减。</p>
2121

22-
<ul>
23-
<li><code>arr.length &gt;= 3</code></li>
24-
<li>存在 <code>i</code>(<code>0 &lt; i&nbsp;&lt; arr.length - 1</code>)使得:
25-
<ul>
26-
<li><code>arr[0] &lt; arr[1] &lt; ... arr[i-1] &lt; arr[i] </code></li>
27-
<li><code>arr[i] &gt; arr[i+1] &gt; ... &gt; arr[arr.length - 1]</code></li>
28-
</ul>
29-
</li>
30-
</ul>
31-
32-
<p>给你由整数组成的山脉数组 <code>arr</code> ,返回满足 <code>arr[0] &lt; arr[1] &lt; ... arr[i - 1] &lt; arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code> 的下标 <code>i</code> 。</p>
22+
<p>返回峰值元素的下标。</p>
3323

3424
<p>你必须设计并实现时间复杂度为 <code>O(log(n))</code> 的解决方案。</p>
3525

@@ -63,7 +53,7 @@ tags:
6353
<ul>
6454
<li><code>3 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
6555
<li><code>0 &lt;= arr[i] &lt;= 10<sup>6</sup></code></li>
66-
<li>题目数据保证 <code>arr</code> 是一个山脉数组</li>
56+
<li>题目数据 <strong>保证</strong> <code>arr</code> 是一个山脉数组</li>
6757
</ul>
6858

6959
<!-- description:end -->

solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md

+18-25
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,36 @@ tags:
1717

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

20-
<p>An array <code>arr</code> is a <strong>mountain</strong> if the following properties hold:</p>
20+
<p>You are given an integer <strong>mountain</strong> array <code>arr</code> of length <code>n</code> where the values increase to a <strong>peak element</strong> and then decrease.</p>
2121

22-
<ul>
23-
<li><code>arr.length &gt;= 3</code></li>
24-
<li>There exists some <code>i</code> with <code>0 &lt; i &lt; arr.length - 1</code> such that:
25-
<ul>
26-
<li><code>arr[0] &lt; arr[1] &lt; ... &lt; arr[i - 1] &lt; arr[i] </code></li>
27-
<li><code>arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code></li>
28-
</ul>
29-
</li>
30-
</ul>
31-
32-
<p>Given a mountain array <code>arr</code>, return the index <code>i</code> such that <code>arr[0] &lt; arr[1] &lt; ... &lt; arr[i - 1] &lt; arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code>.</p>
22+
<p>Return the index of the peak element.</p>
3323

34-
<p>You must solve it in <code>O(log(arr.length))</code> time complexity.</p>
24+
<p>Your task is to solve it in <code>O(log(n))</code> time complexity.</p>
3525

3626
<p>&nbsp;</p>
3727
<p><strong class="example">Example 1:</strong></p>
3828

39-
<pre>
40-
<strong>Input:</strong> arr = [0,1,0]
41-
<strong>Output:</strong> 1
42-
</pre>
29+
<div class="example-block">
30+
<p><strong>Input:</strong> <span class="example-io">arr = [0,1,0]</span></p>
31+
32+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
33+
</div>
4334

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

46-
<pre>
47-
<strong>Input:</strong> arr = [0,2,1,0]
48-
<strong>Output:</strong> 1
49-
</pre>
37+
<div class="example-block">
38+
<p><strong>Input:</strong> <span class="example-io">arr = [0,2,1,0]</span></p>
39+
40+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
41+
</div>
5042

5143
<p><strong class="example">Example 3:</strong></p>
5244

53-
<pre>
54-
<strong>Input:</strong> arr = [0,10,5,2]
55-
<strong>Output:</strong> 1
56-
</pre>
45+
<div class="example-block">
46+
<p><strong>Input:</strong> <span class="example-io">arr = [0,10,5,2]</span></p>
47+
48+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
49+
</div>
5750

5851
<p>&nbsp;</p>
5952
<p><strong>Constraints:</strong></p>

solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ tags:
2323

2424
<ul>
2525
<li>
26-
<p>如果当前数字为偶数,则将其除以 2 。</p>
26+
<p>如果当前数字为偶数,则将其除以 <code>2</code> 。</p>
2727
</li>
2828
<li>
29-
<p>如果当前数字为奇数,则将其加上 1 。</p>
29+
<p>如果当前数字为奇数,则将其加上 <code>1</code> 。</p>
3030
</li>
3131
</ul>
3232

@@ -36,9 +36,10 @@ tags:
3636

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

39-
<pre><strong>输入:</strong>s = &quot;1101&quot;
39+
<pre>
40+
<strong>输入:</strong>s = "1101"
4041
<strong>输出:</strong>6
41-
<strong>解释:</strong>&quot;1101&quot; 表示十进制数 13 。
42+
<strong>解释:</strong>"1101" 表示十进制数 13 。
4243
Step 1) 13 是奇数,加 1 得到 14&nbsp;
4344
Step 2) 14 是偶数,除 2 得到 7
4445
Step 3) 7 是奇数,加 1 得到 8
@@ -49,15 +50,17 @@ Step 6) 2 是偶数,除 2 得到 1&nbsp;
4950

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

52-
<pre><strong>输入:</strong>s = &quot;10&quot;
53+
<pre>
54+
<strong>输入:</strong>s = "10"
5355
<strong>输出:</strong>1
54-
<strong>解释:</strong>&quot;10&quot; 表示十进制数 2 。
56+
<strong>解释:</strong>"10" 表示十进制数 2 。
5557
Step 1) 2 是偶数,除 2 得到 1
5658
</pre>
5759

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

60-
<pre><strong>输入:</strong>s = &quot;1&quot;
62+
<pre>
63+
<strong>输入:</strong>s = "1"
6164
<strong>输出:</strong>0
6265
</pre>
6366

@@ -67,8 +70,8 @@ Step 1) 2 是偶数,除 2 得到 1
6770

6871
<ul>
6972
<li><code>1 &lt;= s.length&nbsp;&lt;= 500</code></li>
70-
<li><code>s</code> 由字符 <code>&#39;0&#39;</code> 或 <code>&#39;1&#39;</code> 组成。</li>
71-
<li><code>s[0] == &#39;1&#39;</code></li>
73+
<li><code>s</code> 由字符 <code>'0'</code> 或 <code>'1'</code> 组成。</li>
74+
<li><code>s[0] == '1'</code></li>
7275
</ul>
7376

7477
<!-- description:end -->

solution/1400-1499/1404.Number of Steps to Reduce a Number in Binary Representation to One/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Step 6) 2 is even, divide by 2 and obtain 1.&nbsp;
5252
<pre>
5353
<strong>Input:</strong> s = &quot;10&quot;
5454
<strong>Output:</strong> 1
55-
<strong>Explanation:</strong> &quot;10&quot; corressponds to number 2 in their decimal representation.
55+
<strong>Explanation:</strong> &quot;10&quot; corresponds to number 2 in their decimal representation.
5656
Step 1) 2 is even, divide by 2 and obtain 1.&nbsp;
5757
</pre>
5858

solution/2000-2099/2061.Number of Spaces Cleaning Robot Cleaned/README_EN.md

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

2323
<p>A cleaning robot starts at the top left corner of the room and is facing right. The robot will continue heading straight until it reaches the edge of the room or it hits an object, after which it will turn 90 degrees <strong>clockwise</strong> and repeat this process. The starting space and all spaces that the robot visits are <strong>cleaned</strong> by it.</p>
2424

25-
<p>Return <em>the number of <strong>clean</strong> spaces in the room if the robot runs indefinetely.</em></p>
25+
<p>Return <em>the number of <strong>clean</strong> spaces in the room if the robot runs indefinitely.</em></p>
2626

2727
<p>&nbsp;</p>
2828
<p><strong class="example">Example 1:</strong></p>

solution/contest.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)