Skip to content
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
2 changes: 1 addition & 1 deletion lcof2/剑指 Offer II 052. 展平二叉搜索树/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class Solution {
var tail: TreeNode? = nil
var stack = [TreeNode]()
var cur = root

while !stack.isEmpty || cur != nil {
while cur != nil {
stack.append(cur!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ tags:
<p><strong>进阶:</strong></p>

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

<p>&nbsp;</p>
Expand Down
53 changes: 39 additions & 14 deletions solution/0200-0299/0249.Group Shifted Strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,50 @@ tags:

<!-- description:start -->

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

<pre>&quot;abc&quot; -&gt; &quot;bcd&quot; -&gt; ... -&gt; &quot;xyz&quot;</pre>
<ul>
<li><strong>右移</strong>:将字符串中每个字母都变为其在字母表中 <strong>后续</strong> 的字母,其中用 'a' 替换 'z'。比如,<code>"abc"</code>&nbsp;能够右移为&nbsp;<code>"bcd"</code>,<code>"xyz"</code>&nbsp;能够右移为&nbsp;<code>"yza"</code>。</li>
<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>
</ul>

<p>给定一个包含仅小写字母字符串的列表,将该列表中所有满足&nbsp;&ldquo;移位&rdquo; 操作规律的组合进行分组并返回。</p>
<p>我们可以不断地向两个方向移动字符串,形成 <strong>无限的移位序列</strong>。</p>

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

<p>给定一个字符串数组&nbsp;<code>strings</code>,将属于相同移位序列的所有&nbsp;<code>strings[i]</code>&nbsp;进行分组。你可以以 <strong>任意顺序</strong> 返回答案。</p>

<p>&nbsp;</p>

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

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">strings = ["abc","bcd","acef","xyz","az","ba","a","z"]</span></p>

<p><strong>输出:</strong><span class="example-io">[["acef"],["a","z"],["abc","bcd","xyz"],["az","ba"]]</span></p>

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

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

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">strings = ["a"]</span></p>

<p><strong>输出:</strong><span class="example-io">[["a"]]</span></p>

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

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

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

<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>
<strong>输出:</strong>
[
[&quot;abc&quot;,&quot;bcd&quot;,&quot;xyz&quot;],
[&quot;az&quot;,&quot;ba&quot;],
[&quot;acef&quot;],
[&quot;a&quot;,&quot;z&quot;]
]
<strong>解释:</strong>可以认为字母表首尾相接,所以 &#39;z&#39; 的后续为 &#39;a&#39;,所以 [&quot;az&quot;,&quot;ba&quot;] 也满足 &ldquo;移位&rdquo; 操作规律。</pre>
<ul>
<li><code>1 &lt;= strings.length &lt;= 200</code></li>
<li><code>1 &lt;= strings[i].length &lt;= 50</code></li>
<li><code>strings[i]</code>&nbsp;只包含小写英文字母。</li>
</ul>

<!-- description:end -->

Expand Down
4 changes: 2 additions & 2 deletions solution/0600-0699/0648.Replace Words/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ tags:

<!-- description:start -->

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions solution/0600-0699/0648.Replace Words/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ tags:

<!-- description:start -->

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

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

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

Expand Down
16 changes: 3 additions & 13 deletions solution/0800-0899/0852.Peak Index in a Mountain Array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@ tags:

<!-- description:start -->

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

<ul>
<li><code>arr.length &gt;= 3</code></li>
<li>存在 <code>i</code>(<code>0 &lt; i&nbsp;&lt; arr.length - 1</code>)使得:
<ul>
<li><code>arr[0] &lt; arr[1] &lt; ... arr[i-1] &lt; arr[i] </code></li>
<li><code>arr[i] &gt; arr[i+1] &gt; ... &gt; arr[arr.length - 1]</code></li>
</ul>
</li>
</ul>

<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>
<p>返回峰值元素的下标。</p>

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

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

<!-- description:end -->
Expand Down
43 changes: 18 additions & 25 deletions solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,36 @@ tags:

<!-- description:start -->

<p>An array <code>arr</code> is a <strong>mountain</strong> if the following properties hold:</p>
<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>

<ul>
<li><code>arr.length &gt;= 3</code></li>
<li>There exists some <code>i</code> with <code>0 &lt; i &lt; arr.length - 1</code> such that:
<ul>
<li><code>arr[0] &lt; arr[1] &lt; ... &lt; arr[i - 1] &lt; arr[i] </code></li>
<li><code>arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code></li>
</ul>
</li>
</ul>

<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>
<p>Return the index of the peak element.</p>

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

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

<pre>
<strong>Input:</strong> arr = [0,1,0]
<strong>Output:</strong> 1
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">arr = [0,1,0]</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>

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

<pre>
<strong>Input:</strong> arr = [0,2,1,0]
<strong>Output:</strong> 1
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">arr = [0,2,1,0]</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>

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

<pre>
<strong>Input:</strong> arr = [0,10,5,2]
<strong>Output:</strong> 1
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">arr = [0,10,5,2]</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ tags:

<ul>
<li>
<p>如果当前数字为偶数,则将其除以 2 。</p>
<p>如果当前数字为偶数,则将其除以 <code>2</code> 。</p>
</li>
<li>
<p>如果当前数字为奇数,则将其加上 1 。</p>
<p>如果当前数字为奇数,则将其加上 <code>1</code> 。</p>
</li>
</ul>

Expand All @@ -36,9 +36,10 @@ tags:

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

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

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

<pre><strong>输入:</strong>s = &quot;10&quot;
<pre>
<strong>输入:</strong>s = "10"
<strong>输出:</strong>1
<strong>解释:</strong>&quot;10&quot; 表示十进制数 2 。
<strong>解释:</strong>"10" 表示十进制数 2 。
Step 1) 2 是偶数,除 2 得到 1
</pre>

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

<pre><strong>输入:</strong>s = &quot;1&quot;
<pre>
<strong>输入:</strong>s = "1"
<strong>输出:</strong>0
</pre>

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

<ul>
<li><code>1 &lt;= s.length&nbsp;&lt;= 500</code></li>
<li><code>s</code> 由字符 <code>&#39;0&#39;</code> 或 <code>&#39;1&#39;</code> 组成。</li>
<li><code>s[0] == &#39;1&#39;</code></li>
<li><code>s</code> 由字符 <code>'0'</code> 或 <code>'1'</code> 组成。</li>
<li><code>s[0] == '1'</code></li>
</ul>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Step 6) 2 is even, divide by 2 and obtain 1.&nbsp;
<pre>
<strong>Input:</strong> s = &quot;10&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> &quot;10&quot; corressponds to number 2 in their decimal representation.
<strong>Explanation:</strong> &quot;10&quot; corresponds to number 2 in their decimal representation.
Step 1) 2 is even, divide by 2 and obtain 1.&nbsp;
</pre>

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

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

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

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/contest.json

Large diffs are not rendered by default.