Skip to content

Commit

Permalink
chore: update lc problems (doocs#1712)
Browse files Browse the repository at this point in the history
* chore: update lc problems

* chore: optimised images with calibre/image-actions

---------

Co-authored-by: Doocs Bot <[email protected]>
  • Loading branch information
yanglbme and idoocs authored Sep 27, 2023
1 parent 435f106 commit 54c4475
Show file tree
Hide file tree
Showing 189 changed files with 1,238 additions and 1,094 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

<p>给你一个 <strong>升序排列</strong> 的数组 <code>nums</code> ,请你<strong><a href="http://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank"> 原地</a></strong> 删除重复出现的元素,使每个元素 <strong>只出现一次</strong> ,返回删除后数组的新长度。元素的 <strong>相对顺序</strong> 应该保持 <strong>一致</strong> 。然后返回 <code>nums</code> 中唯一元素的个数。</p>
<p>给你一个 <strong>非严格递增排列</strong> 的数组 <code>nums</code> ,请你<strong><a href="http://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank"> 原地</a></strong> 删除重复出现的元素,使每个元素 <strong>只出现一次</strong> ,返回删除后数组的新长度。元素的 <strong>相对顺序</strong> 应该保持 <strong>一致</strong> 。然后返回 <code>nums</code> 中唯一元素的个数。</p>

<p>考虑 <code>nums</code> 的唯一元素的数量为 <code>k</code> ,你需要做以下事情确保你的题解可以被通过:</p>

Expand Down Expand Up @@ -57,7 +57,7 @@ for (int i = 0; i &lt; k; i++) {
<ul>
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
<li><code>nums</code> 已按 <strong>升序</strong> 排列</li>
<li><code>nums</code> 已按 <strong>非严格递增</strong>&nbsp;排列</li>
</ul>

## 解法
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [138. 复制带随机指针的链表](https://leetcode.cn/problems/copy-list-with-random-pointer)
# [138. 随机链表的复制](https://leetcode.cn/problems/copy-list-with-random-pointer)

[English Version](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md)

Expand Down Expand Up @@ -62,6 +62,10 @@
<li><code>Node.random</code>&nbsp;为&nbsp;<code>null</code> 或指向链表中的节点。</li>
</ul>

<p>注意:本题与主站 138 题相同:<a href="https://leetcode.cn/problems/copy-list-with-random-pointer/" rel="noopener noreferrer" target="_blank">https://leetcode.cn/problems/copy-list-with-random-pointer/</a></p>

<p>&nbsp;</p>

## 解法

<!-- 这里可写通用的实现逻辑 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p>题目数据 <strong>保证</strong> 数组&nbsp;<code>nums</code>之中任意元素的全部前缀元素和后缀的乘积都在&nbsp; <strong>32 位</strong> 整数范围内。</p>

<p>请<strong>不要使用除法,</strong>且在&nbsp;<code>O(<em>n</em>)</code> 时间复杂度内完成此题。</p>
<p>请&nbsp;<strong>不要使用除法,</strong>且在&nbsp;<code>O(<em>n</em>)</code> 时间复杂度内完成此题。</p>

<p>&nbsp;</p>

Expand Down Expand Up @@ -40,7 +40,7 @@

<p>&nbsp;</p>

<p><strong>进阶:</strong>你可以在 <code>O(1)</code>&nbsp;的额外空间复杂度内完成这个题目吗?( 出于对空间复杂度分析的目的,输出数组<strong>不被视为</strong>额外空间。)</p>
<p><strong>进阶:</strong>你可以在 <code>O(1)</code>&nbsp;的额外空间复杂度内完成这个题目吗?( 出于对空间复杂度分析的目的,输出数组&nbsp;<strong>不被视为&nbsp;</strong>额外空间。)</p>

## 解法

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ul>

<p>&nbsp;</p>
<p><strong>Follow up:</strong>&nbsp;Can you solve the problem in <code>O(1)&nbsp;</code>extra&nbsp;space complexity? (The output array <strong>does not</strong> count as extra space for space complexity analysis.)</p>
<p><strong>Follow up:</strong>&nbsp;Can you solve the problem in <code>O(1)</code>&nbsp;extra&nbsp;space complexity? (The output array <strong>does not</strong> count as extra space for space complexity analysis.)</p>

## Solutions

Expand Down
2 changes: 1 addition & 1 deletion solution/0400-0499/0460.LFU Cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ul>
<li><code>LFUCache(int capacity)</code> - 用数据结构的容量&nbsp;<code>capacity</code> 初始化对象</li>
<li><code>int get(int key)</code>&nbsp;- 如果键&nbsp;<code>key</code> 存在于缓存中,则获取键的值,否则返回 <code>-1</code> 。</li>
<li><code>void put(int key, int value)</code>&nbsp;- 如果键&nbsp;<code>key</code> 已存在,则变更其值;如果键不存在,请插入键值对。当缓存达到其容量&nbsp;<code>capacity</code> 时,则应该在插入新项之前,移除最不经常使用的项。在此问题中,当存在平局(即两个或更多个键具有相同使用频率)时,应该去除 <strong>最近最久未使用</strong> 的键。</li>
<li><code>void put(int key, int value)</code>&nbsp;- 如果键&nbsp;<code>key</code> 已存在,则变更其值;如果键不存在,请插入键值对。当缓存达到其容量&nbsp;<code>capacity</code> 时,则应该在插入新项之前,移除最不经常使用的项。在此问题中,当存在平局(即两个或更多个键具有相同使用频率)时,应该去除 <strong>最久未使用</strong> 的键。</li>
</ul>

<p>为了确定最不常使用的键,可以为缓存中的每个键维护一个 <strong>使用计数器</strong> 。使用计数最小的键是最久未使用的键。</p>
Expand Down
18 changes: 9 additions & 9 deletions solution/0400-0499/0475.Heaters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@

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

<p>冬季已经来临。 你的任务是设计一个有固定加热半径的供暖器向所有房屋供暖。</p>
<p>冬季已经来临。&nbsp;你的任务是设计一个有固定加热半径的供暖器向所有房屋供暖。</p>

<p>在加热器的加热半径范围内的每个房屋都可以获得供暖。</p>

<p>现在,给出位于一条水平线上的房屋 <code>houses</code> 和供暖器 <code>heaters</code> 的位置,请你找出并返回可以覆盖所有房屋的最小加热半径。</p>
<p>现在,给出位于一条水平线上的房屋&nbsp;<code>houses</code> 和供暖器&nbsp;<code>heaters</code> 的位置,请你找出并返回可以覆盖所有房屋的最小加热半径。</p>

<p><strong>说明</strong>:所有供暖器都遵循你的半径标准,加热的半径也一样。</p>
<p><b>注意</b>:所有供暖器 <code>heaters</code> 都遵循你的半径标准,加热的半径也一样。</p>

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

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

<pre>
<strong>输入:</strong> houses = [1,2,3], heaters = [2]
<strong>输出:</strong> 1
<strong>解释:</strong> 仅在位置2上有一个供暖器。如果我们将加热半径设为1,那么所有房屋就都能得到供暖。
<strong>解释:</strong> 仅在位置 2 上有一个供暖器。如果我们将加热半径设为 1,那么所有房屋就都能得到供暖。
</pre>

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

<pre>
<strong>输入:</strong> houses = [1,2,3,4], heaters = [1,4]
<strong>输出:</strong> 1
<strong>解释:</strong> 在位置1, 4上有两个供暖器。我们需要将加热半径设为1,这样所有房屋就都能得到供暖。
<strong>解释:</strong> 在位置 1, 4 上有两个供暖器。我们需要将加热半径设为 1,这样所有房屋就都能得到供暖。
</pre>

<p><strong>示例 3:</strong></p>
Expand All @@ -39,13 +39,13 @@
<strong>输出:</strong>3
</pre>

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

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

<ul>
<li><code>1 <= houses.length, heaters.length <= 3 * 10<sup>4</sup></code></li>
<li><code>1 <= houses[i], heaters[i] <= 10<sup>9</sup></code></li>
<li><code>1 &lt;= houses.length, heaters.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= houses[i], heaters[i] &lt;= 10<sup>9</sup></code></li>
</ul>

## 解法
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 @@ -26,7 +26,7 @@
<pre>
<strong>Input:</strong> houses = [1,2,3,4], heaters = [1,4]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The two heater was placed in the position 1 and 4. We need to use radius 1 standard, then all the houses can be warmed.
<strong>Explanation:</strong> The two heaters were placed at positions 1 and 4. We need to use a radius 1 standard, then all the houses can be warmed.
</pre>

<p><strong class="example">Example 3:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/0500-0599/0533.Lonely Pixel II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0533.Lonely%20Pixel%20II/images/pixel2-1-grid.jpg" style="width: 493px; height: 333px;" />
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0533.Lonely%20Pixel%20II/images/1694957797-UWXAxl-image.png" style="width: 493px; height: 333px;" />
<pre>
<strong>输入:</strong>picture = [["W","B","W","B","B","W"],["W","B","W","B","B","W"],["W","B","W","B","B","W"],["W","W","B","W","B","W"]], target = 3
<strong>输出:</strong>6
Expand All @@ -29,7 +29,7 @@
</pre>

<p><strong>示例 2:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0533.Lonely%20Pixel%20II/images/pixel2-2-grid.jpg" style="width: 253px; height: 253px;" />
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0533.Lonely%20Pixel%20II/images/1694957806-FyCCMF-image.png" style="width: 253px; height: 253px;" />
<pre>
<strong>输入:</strong>picture = [["W","W","B"],["W","W","B"],["W","W","B"]], target = 1
<strong>输出:</strong>0
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 22 additions & 26 deletions solution/0500-0599/0544.Output Contest Matches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@

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

<p>在 NBA 季后赛中,我们总是安排较强的队伍对战较弱的队伍,例如用排名第 1 的队伍和第 n 的队伍对决,这是一个可以让比赛更加有趣的好策略。现在,给你&nbsp;<strong>n&nbsp;</strong>支队伍,你需要以字符串格式输出它们的&nbsp;<strong>最终&nbsp;</strong>比赛配对。</p>
<p>&nbsp;</p>

<p><strong>n </strong>支队伍按从 1 到 n 的正整数格式给出,分别代表它们的初始排名(排名 1 最强,排名 n 最弱)。我们用括号(&#39;(&#39;, &#39;)&#39;)和逗号(&#39;,&#39;)来表示匹配对&mdash;&mdash;括号(&#39;(&#39;, &#39;)&#39;)表示匹配,逗号(&#39;,&#39;)来用于分割。&nbsp;在每一轮的匹配过程中,你都需要遵循将强队与弱队配对的原则。</p>
<p>在 NBA 季后赛期间,我们总是安排相对强大的球队与相对弱小的球队比赛,就像让排名第 <code>1</code> 的球队与排名第 <code>n</code> 的球队比赛一样,这是一种使比赛更加有趣的好策略。</p>

<p>&nbsp;</p>
<p>现给定 <code>n</code> 支球队,请以字符串的形式返回它们的最终的比赛匹配方案。</p>

<p><strong>示例 1:</strong></p>
<p>这 <code>n</code> 支球队从 <code>1</code> 到 <code>n</code> 进行标记,代表它们的初始排名(即,排名 <code>1</code> 的是最强的球队,排名 <code>n</code> 的是最弱的球队)。</p>

<pre><strong>输入:</strong> 2
<strong>输出:</strong> (1,2)
<strong>解析:</strong>
初始地,我们有队1和队2两支队伍,按照1,2排列。
因此 用 &#39;(&#39;, &#39;)&#39;&#39;,&#39;来将队1和队2进行配对,得到最终答案。
</pre>
<p>我们将使用括号 <code>'('</code> 和 <code>')'</code> 以及逗号 <code>','</code> 来表示比赛的匹配情况。我们使用括号来表示匹配,逗号来表示分组。在每一轮的匹配过程中,你总是需要遵循使相对强大的球队与相对弱小的球队配对的策略。</p>

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

<pre><strong>输入:</strong> 4
<strong>输出:</strong> ((1,4),(2,3))
<strong>解析:</strong>
在第一轮,我们将队伍1和4配对,2和3配对,以满足将强队和弱队搭配的效果。得到(1,4),(2,3).
<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong> n = 4
<strong>输出:</strong> "((1,4),(2,3))"
<strong>解释:</strong>
在第一轮,我们将队伍 1 和 4 配对,2 和 3 配对,以满足将强队和弱队搭配的效果。得到(1,4),(2,3).
在第二轮,(1,4) 和 (2,3) 的赢家需要进行比赛以确定最终赢家,因此需要再在外面加一层括号。
于是最终答案是((1,4),(2,3))。
</pre>

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

<pre><strong>输入:</strong> 8
<strong>输出:</strong> (((1,8),(4,5)),((2,7),(3,6)))
<strong>解析:</strong>
<pre>
<strong>输入:</strong> n = 8
<strong>输出:</strong> "(((1,8),(4,5)),((2,7),(3,6)))"
<strong>解释:</strong>
第一轮: (1,8),(2,7),(3,6),(4,5)
第二轮: ((1,8),(4,5)),((2,7),(3,6))
第三轮 (((1,8),(4,5)),((2,7),(3,6)))
Expand All @@ -44,14 +43,11 @@

<p>&nbsp;</p>

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

<ol>
<li><strong>n&nbsp;</strong>的范围是&nbsp;[2, 2<sup>12</sup>].</li>
<li>保证 n 可以写成&nbsp;2<sup>k</sup>&nbsp;的形式,其中 k 是正整数。</li>
</ol>

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

## 解法

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Description

<p>During the NBA playoffs, we always set the rather strong team to play with the rather weak team, like make the rank <code>1</code> team play with the rank <code>n<sup>th</sup></code> team, which is a good strategy to make the contest more interesting.</p>
<p>During the NBA playoffs, we always set the rather strong team to play with the rather weak team, like making&nbsp;the rank <code>1</code> team play with the rank <code>n<sup>th</sup></code> team, which is a good strategy to make the contest more interesting.</p>

<p>Given <code>n</code> teams, return <em>their final contest matches in the form of a string</em>.</p>

Expand Down
2 changes: 1 addition & 1 deletion solution/0600-0699/0626.Exchange Seats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| student | varchar |
+-------------+---------+
<code>id</code> 是该表的主键(唯一值)列。
该表的每一行都表示学生的姓名和 ID。
Expand Down
8 changes: 4 additions & 4 deletions solution/0700-0799/0735.Asteroid Collision/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# [735. 行星碰撞](https://leetcode.cn/problems/asteroid-collision)
# [735. 小行星碰撞](https://leetcode.cn/problems/asteroid-collision)

[English Version](/solution/0700-0799/0735.Asteroid%20Collision/README_EN.md)

## 题目描述

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

<p>给定一个整数数组 <code>asteroids</code>,表示在同一行的行星。</p>
<p>给定一个整数数组 <code>asteroids</code>,表示在同一行的小行星。</p>

<p>对于数组中的每一个元素,其绝对值表示行星的大小,正负表示行星的移动方向(正表示向右移动,负表示向左移动)。每一颗行星以相同的速度移动。</p>
<p>对于数组中的每一个元素,其绝对值表示小行星的大小,正负表示小行星的移动方向(正表示向右移动,负表示向左移动)。每一颗小行星以相同的速度移动。</p>

<p>找出碰撞后剩下的所有行星。碰撞规则:两个行星相互碰撞,较小的行星会爆炸。如果两颗行星大小相同,则两颗行星都会爆炸。两颗移动方向相同的行星,永远不会发生碰撞。</p>
<p>找出碰撞后剩下的所有小行星。碰撞规则:两个小行星相互碰撞,较小的小行星会爆炸。如果两颗小行星大小相同,则两颗小行星都会爆炸。两颗移动方向相同的小行星,永远不会发生碰撞。</p>

<p>&nbsp;</p>

Expand Down
10 changes: 5 additions & 5 deletions solution/0900-0999/0944.Delete Columns to Make Sorted/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ abc
bce
cae</pre>

<p>你需要找出并删除 <strong>不是按字典序升序排列的</strong> 列。在上面的例子(下标从 0 开始)中,列 0(<code>'a'</code>, <code>'b'</code>, <code>'c'</code>)和列 2(<code>'c'</code>, <code>'e'</code>, <code>'e'</code>)都是按升序排列的,而列 1(<code>'b'</code>, <code>'c'</code>, <code>'a'</code>)不是,所以要删除列 1 。</p>
<p>你需要找出并删除 <strong>不是按字典序非严格递增排列的</strong> 列。在上面的例子(下标从 0 开始)中,列 0(<code>'a'</code>, <code>'b'</code>, <code>'c'</code>)和列 2(<code>'c'</code>, <code>'e'</code>, <code>'e'</code>)都是按字典序非严格递增排列的,而列 1(<code>'b'</code>, <code>'c'</code>, <code>'a'</code>)不是,所以要删除列 1 。</p>

<p>返回你需要删除的列数。</p>

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

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

Expand Down Expand Up @@ -56,14 +56,14 @@ cae</pre>
所有 3 列都是非升序排列的,所以都要删除。
</pre>

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

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

<ul>
<li><code>n == strs.length</code></li>
<li><code>1 <= n <= 100</code></li>
<li><code>1 <= strs[i].length <= 1000</code></li>
<li><code>1 &lt;= n &lt;= 100</code></li>
<li><code>1 &lt;= strs[i].length &lt;= 1000</code></li>
<li><code>strs[i]</code> 由小写英文字母组成</li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<pre>
<strong>输入:</strong>text = "antaprezatepzapreanta"
<strong>输出:</strong>11
<strong>解释:</strong>我们可以把字符串拆分成 "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)"。
<strong>解释:</strong>我们可以把字符串拆分成 "(a)(nt)(a)(pre)(za)(tep)(za)(pre)(a)(nt)(a)"。
</pre>

<p>&nbsp;</p>
Expand Down
10 changes: 5 additions & 5 deletions solution/1100-1199/1164.Product Price at a Given Date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
| new_price | int |
| change_date | date |
+---------------+---------+
这张表的主键是 (product_id, change_date)。
(product_id, change_date) 是此表的主键(具有唯一值的列组合)
这张表的每一行分别记录了 某产品 在某个日期 更改后 的新价格。</pre>

<p>&nbsp;</p>

<p>写一段 SQL来查找在&nbsp;<code>2019-08-16</code><strong> </strong>时全部产品的价格,假设所有产品在修改前的价格都是&nbsp;<code>10</code><strong> 。</strong></p>
<p>编写一个解决方案,找出在&nbsp;<code>2019-08-16</code><strong> </strong>时全部产品的价格,假设所有产品在修改前的价格都是&nbsp;<code>10</code><strong> 。</strong></p>

<p>以 <strong>任意顺序 </strong>返回结果表。</p>

<p>查询结果格式如下例所示。</p>
<p>结果格式如下例所示。</p>

<p>&nbsp;</p>

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

<pre>
<code><strong>输入:</strong>
Products</code> 表:
<strong>输入:</strong>
Products 表:
+------------+-----------+-------------+
| product_id | new_price | change_date |
+------------+-----------+-------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
| new_price | int |
| change_date | date |
+---------------+---------+
(product_id, change_date) is the primary key of this table.
(product_id, change_date) is the primary key (combination of columns with unique values) of this table.
Each row of this table indicates that the price of some product was changed to a new price at some date.</pre>

<p>&nbsp;</p>

<p>Write an SQL query to find the prices of all products on <code>2019-08-16</code>. Assume the price of all products before any change is <code>10</code>.</p>
<p>Write a solution to find the prices of all products on <code>2019-08-16</code>. Assume the price of all products before any change is <code>10</code>.</p>

<p>Return the result table in <strong>any order</strong>.</p>

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

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

0 comments on commit 54c4475

Please sign in to comment.