Skip to content
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

chore: update lc problems #1922

Merged
merged 1 commit into from
Nov 3, 2023
Merged
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
8 changes: 4 additions & 4 deletions solution/0200-0299/0264.Ugly Number II/README.md
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@

<p>给你一个整数 <code>n</code> ,请你找出并返回第 <code>n</code> 个 <strong>丑数</strong> 。</p>

<p><strong>丑数 </strong>就是只包含质因数 <code>2</code>、<code>3</code> 和/或 <code>5</code> 的正整数。</p>
<p><strong>丑数 </strong>就是质因子只包含&nbsp;<code>2</code>、<code>3</code> 和&nbsp;<code>5</code>&nbsp;的正整数。</p>

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

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

@@ -28,12 +28,12 @@
<strong>解释:</strong>1 通常被视为丑数。
</pre>

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

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

<ul>
<li><code>1 <= n <= 1690</code></li>
<li><code>1 &lt;= n &lt;= 1690</code></li>
</ul>

## 解法
14 changes: 7 additions & 7 deletions solution/0200-0299/0275.H-Index II/README.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

<p>给你一个整数数组 <code>citations</code> ,其中 <code>citations[i]</code> 表示研究者的第 <code>i</code> 篇论文被引用的次数,<code>citations</code> 已经按照&nbsp;<strong>升序排列&nbsp;</strong>。计算并返回该研究者的 h<strong><em>&nbsp;</em></strong>指数。</p>

<p><a href="https://baike.baidu.com/item/h-index/3991452?fr=aladdin" target="_blank">h 指数的定义</a>:h 代表“高引用次数”(high citations),一名科研人员的 <code>h</code> 指数是指他(她)的 (<code>n</code> 篇论文中)<strong>总共</strong>有 <code>h</code> 篇论文分别被引用了<strong>至少</strong> <code>h</code> 次。</p>
<p><a href="https://baike.baidu.com/item/h-index/3991452?fr=aladdin" target="_blank">h 指数的定义</a>:h 代表“高引用次数”(high citations),一名科研人员的 <code>h</code> 指数是指他(她)的 (<code>n</code> 篇论文中)<strong>至少&nbsp;</strong>有 <code>h</code> 篇论文分别被引用了<strong>至少</strong> <code>h</code> 次。</p>

<p>请你设计并实现对数时间复杂度的算法解决此问题。</p>

@@ -17,16 +17,16 @@
<p><strong class="example">示例 1:</strong></p>

<pre>
<strong>输入<code>:</code></strong><code>citations = [0,1,3,5,6]</code>
<strong>输出:</strong>3
<strong>解释:</strong>给定数组表示研究者总共有 <code>5</code> 篇论文,每篇论文相应的被引用了 0<code>, 1, 3, 5, 6</code> 次。
&nbsp; 由于研究者有 <code>3 </code>篇论文每篇<strong> 至少 </strong>被引用了 <code>3</code> 次,其余两篇论文每篇被引用<strong> 不多于</strong> <code>3</code> 次,所以她的<em> h </em>指数是 <code>3</code> 。</pre>
<strong>输入</strong><code>citations = [0,1,3,5,6]</code>
<strong>输出:</strong><code>3</code>
<strong>解释:</strong>给定数组表示研究者总共有 <code>5</code> 篇论文,每篇论文相应的被引用了 <code>0, 1, 3, 5, 6</code> 次。
&nbsp; 由于研究者有<code>3</code>篇论文每篇<strong> 至少 </strong>被引用了 <code>3</code> 次,其余两篇论文每篇被引用<strong> 不多于</strong> <code>3</code> 次,所以她的<em> h </em>指数是 <code>3</code> 。</pre>

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

<pre>
<strong>输入:</strong>citations = [1,2,100]
<strong>输出:</strong>2
<strong>输入:</strong><code>citations = [1,2,100]</code>
<strong>输出:</strong><code>2</code>
</pre>

<p>&nbsp;</p>
2 changes: 1 addition & 1 deletion solution/0400-0499/0484.Find Permutation/README.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
<p>由范围 <code>[1,n]</code> 内所有整数组成的 <code>n</code> 个整数的排列&nbsp;<code>perm</code>&nbsp;可以表示为长度为 <code>n - 1</code> 的字符串 <code>s</code> ,其中:</p>

<ul>
<li>如果 <code>perm[i] &lt; perm[i + 1]</code> ,那么 <code>s[i] == ' i '</code></li>
<li>如果 <code>perm[i] &lt; perm[i + 1]</code> ,那么 <code>s[i] == 'I'</code></li>
<li>如果&nbsp;<code>perm[i] &gt; perm[i + 1]</code>&nbsp;,那么 <code>s[i] == 'D'</code>&nbsp;。</li>
</ul>

Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@
| seat_id | int |
| free | bool |
+-------------+------+
在 SQL 中,Seat_id 是该表的自动递增主键列。
Seat_id 是该表的自动递增主键列。
在 PostgreSQL 中,<code>free</code> 存储为整数。请使用 <code>::boolean</code> 将其转换为布尔格式。
该表的每一行表示第 i 个座位是否空闲。1 表示空闲,0 表示被占用。</pre>

<p>&nbsp;</p>
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
| seat_id | int |
| free | bool |
+-------------+------+
In SQL, seat_id is an auto-increment primary key column for this table.
seat_id is an auto-increment column for this table.
Each row of this table indicates whether the i<sup>th</sup> seat is free or not. 1 means free while 0 means occupied.
</pre>

2 changes: 1 addition & 1 deletion solution/1100-1199/1159.Market Analysis II/README.md
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ item_id 是该表的主键(具有唯一值的列)。

<p>&nbsp;</p>

<p>编写一个解决方案,查找每个用户的加入日期和作为买家在 <code>2019</code> 年下的订单数。</p>
<p>编写一个解决方案,查找每个用户的加入日期和他们作为买家在 <code>2019</code> 年下的订单数。</p>

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

4 changes: 2 additions & 2 deletions solution/1200-1299/1220.Count Vowels Permutation/README_EN.md
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@
<li>Each vowel&nbsp;<code>&#39;e&#39;</code> may only be followed by an <code>&#39;a&#39;</code>&nbsp;or an <code>&#39;i&#39;</code>.</li>
<li>Each vowel&nbsp;<code>&#39;i&#39;</code> <strong>may not</strong> be followed by another <code>&#39;i&#39;</code>.</li>
<li>Each vowel&nbsp;<code>&#39;o&#39;</code> may only be followed by an <code>&#39;i&#39;</code> or a&nbsp;<code>&#39;u&#39;</code>.</li>
<li>Each vowel&nbsp;<code>&#39;u&#39;</code> may only be followed by an <code>&#39;a&#39;.</code></li>
<li>Each vowel&nbsp;<code>&#39;u&#39;</code> may only be followed by an <code>&#39;a&#39;</code>.</li>
</ul>

<p>Since the answer&nbsp;may be too large,&nbsp;return it modulo <code>10^9 + 7.</code></p>
<p>Since the answer&nbsp;may be too large,&nbsp;return it modulo&nbsp;<code>10^9 + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
| name | varchar |
+-------------+---------+
employee_id 是该表中具有唯一值的列。
每一行表示雇员的id 和他的姓名。
每一行表示雇员的 id 和他的姓名。
</pre>

<p>表: <code>Salaries</code></p>
@@ -28,8 +28,8 @@ employee_id 是该表中具有唯一值的列。
| employee_id | int |
| salary | int |
+-------------+---------+
employee_id is 是该表中具有唯一值的列。
每一行表示雇员的id 和他的薪水。
employee_id 是该表中具有唯一值的列。
每一行表示雇员的 id 和他的薪水。
</pre>

<p>&nbsp;</p>
@@ -38,10 +38,10 @@ employee_id is 是该表中具有唯一值的列。

<ul>
<li>雇员的 <strong>姓名</strong> 丢失了,或者</li>
<li>雇员的 <strong>薪水信息</strong> 丢失了,或者</li>
<li>雇员的 <strong>薪水信息</strong> 丢失了</li>
</ul>

<p>返回这些雇员的id &nbsp;<code>employee_id</code>&nbsp;,&nbsp;<strong>从小到大排序&nbsp;</strong>。</p>
<p>返回这些雇员的 id &nbsp;<code>employee_id</code>&nbsp;,&nbsp;<strong>从小到大排序&nbsp;</strong>。</p>

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

@@ -75,9 +75,9 @@ Salaries table:
| 2 |
+-------------+
<strong>解释:</strong>
雇员1,2,4,5 都工作在这个公司
1号雇员的姓名丢失了
2号雇员的薪水信息丢失了。</pre>
雇员 1,2,4,5 都在这个公司工作
1 号雇员的姓名丢失了
2 号雇员的薪水信息丢失了。</pre>

## 解法

Original file line number Diff line number Diff line change
@@ -16,9 +16,10 @@

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2127.Maximum%20Employees%20to%20Be%20Invited%20to%20a%20Meeting/images/ex1.png" style="width: 236px; height: 195px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2127.Maximum%20Employees%20to%20Be%20Invited%20to%20a%20Meeting/images/ex1.png" style="width: 236px; height: 195px;" /></p>

<pre><b>输入:</b>favorite = [2,2,1,2]
<pre>
<b>输入:</b>favorite = [2,2,1,2]
<b>输出:</b>3
<strong>解释:</strong>
上图展示了公司邀请员工 0,1 和 2 参加会议以及他们在圆桌上的座位。
@@ -29,7 +30,8 @@

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

<pre><b>输入:</b>favorite = [1,2,0]
<pre>
<b>输入:</b>favorite = [1,2,0]
<b>输出:</b>3
<b>解释:</b>
每个员工都至少是另一个员工喜欢的员工。所以公司邀请他们所有人参加会议的前提是所有人都参加了会议。
@@ -42,13 +44,14 @@

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2127.Maximum%20Employees%20to%20Be%20Invited%20to%20a%20Meeting/images/ex2.png" style="width: 219px; height: 220px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2127.Maximum%20Employees%20to%20Be%20Invited%20to%20a%20Meeting/images/ex2.png" style="width: 219px; height: 220px;" /></p>

<pre><b>输入:</b>favorite = [3,0,1,4,1]
<pre>
<b>输入:</b>favorite = [3,0,1,4,1]
<b>输出:</b>4
<b>解释:</b>
上图展示了公司可以邀请员工 0,1,3 和 4 参加会议以及他们在圆桌上的座位。
员工 2 无法参加,因为他喜欢的员工 0 旁边的座位已经被占领了。
员工 2 无法参加,因为他喜欢的员工 1 旁边的座位已经被占领了。
所以公司只能不邀请员工 2 。
参加会议的最多员工数目为 4 。
</pre>
Original file line number Diff line number Diff line change
@@ -14,23 +14,23 @@
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> beans = [4,<u><strong>1</strong></u>,6,5]
<strong>Input:</strong> beans = [4,1,6,5]
<strong>Output:</strong> 4
<strong>Explanation:</strong>
- We remove 1 bean from the bag with only 1 bean.
This results in the remaining bags: [4,<b><u>0</u></b>,6,5]
This results in the remaining bags: [4,<strong><u>0</u></strong>,6,5]
- Then we remove 2 beans from the bag with 6 beans.
This results in the remaining bags: [4,0,<strong><u>4</u></strong>,5]
- Then we remove 1 bean from the bag with 5 beans.
This results in the remaining bags: [4,0,4,<b><u>4</u></b>]
This results in the remaining bags: [4,0,4,<strong><u>4</u></strong>]
We removed a total of 1 + 2 + 1 = 4 beans to make the remaining non-empty bags have an equal number of beans.
There are no other solutions that remove 4 beans or fewer.
</pre>

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

<pre>
<strong>Input:</strong> beans = [<strong><u>2</u></strong>,10,<u><strong>3</strong></u>,<strong><u>2</u></strong>]
<strong>Input:</strong> beans = [2,10,3,2]
<strong>Output:</strong> 7
<strong>Explanation:</strong>
- We remove 2 beans from one of the bags with 2 beans.
4 changes: 1 addition & 3 deletions solution/2500-2599/2561.Rearranging Fruits/README.md
Original file line number Diff line number Diff line change
@@ -6,9 +6,7 @@

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

<p>你有两个果篮,每个果篮中有 <code>n</code> 个水果。给你两个下标从 <strong>0</strong> 开始的整数数组 <code>basket1</code> 和 <code>basket2</code> ,用以表示两个果篮中每个水果的成本。</p>

<p>你希望两个果篮相等。为此,可以根据需要多次执行下述操作:</p>
<p>你有两个果篮,每个果篮中有 <code>n</code> 个水果。给你两个下标从 <strong>0</strong> 开始的整数数组 <code>basket1</code> 和 <code>basket2</code> ,用以表示两个果篮中每个水果的交换成本。为了让两个果篮中水果的数量相等。为此,可以根据需要多次执行下述操作:</p>

<ul>
<li>选中两个下标 <code>i</code> 和 <code>j</code> ,并交换 <code>basket1</code> 中的第 <code>i</code> 个水果和 <code>basket2</code> 中的第 <code>j</code> 个水果。</li>
2 changes: 1 addition & 1 deletion solution/2500-2599/2561.Rearranging Fruits/README_EN.md
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
<p><strong>Constraints:</strong></p>

<ul>
<li><code>basket1.length == </code>basket2<code>.length</code></li>
<li><code>basket1.length == basket2.length</code></li>
<li><code>1 &lt;= basket1.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= basket1[i],basket2[i]&nbsp;&lt;= 10<sup>9</sup></code></li>
</ul>
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
<b>输入:</b>nodes = [[0,-1],[1,0],[2,0],[3,2],[4,2]]
<b>输出:</b>true
<b>解释:</b>给定的 nodes 数组可以构成下面图片中的树。
我们可以验证这是树的前序遍历,首先访问节点 0,然后对右子节点进行前序遍历,即 [1] ,然后对左子节点进行前序遍历,即 [2,3,4] 。
我们可以验证这是树的前序遍历,首先访问节点 0,然后对左子节点进行前序遍历,即 [1] ,然后对右子节点进行前序遍历,即 [2,3,4] 。
</pre>

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2700-2799/2764.is%20Array%20a%20Preorder%20of%20Some%20%E2%80%8CBinary%20Tree/images/1.png" style="padding: 10px; background: #fff; border-radius: .5rem; width: 250px; height: 251px;" /></p>
@@ -33,7 +33,7 @@
<b>输入:</b>nodes = [[0,-1],[1,0],[2,0],[3,1],[4,1]]
<b>输出:</b>false
<b>解释:</b>给定的 nodes 数组可以构成下面图片中的树。
对于前序遍历,首先访问节点 0,然后对右子节点进行前序遍历,即 [1,3,4],但是我们可以看到在给定的顺序中,2 位于 1 和 3 之间,因此它不是树的前序遍历。
对于前序遍历,首先访问节点 0,然后对左子节点进行前序遍历,即 [1,3,4],但是我们可以看到在给定的顺序中,2 位于 1 和 3 之间,因此它不是树的前序遍历。
</pre>

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2700-2799/2764.is%20Array%20a%20Preorder%20of%20Some%20%E2%80%8CBinary%20Tree/images/2.png" style="padding: 10px; background: #fff; border-radius: .5rem; width: 250px; height: 251px;" /></p>
Original file line number Diff line number Diff line change
@@ -16,18 +16,20 @@

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

<pre><strong>输入:</strong>nums = [1,2,3,4]
<pre>
<strong>输入:</strong>nums = [1,2,3,4]
<strong>输出:</strong>21
<strong>解释:</strong>nums 中共有 3 个特殊元素:nums[1] ,因为 4 被 1 整除;nums[2] ,因为 4 被 2 整除;以及 nums[4] ,因为 4 被 4 整除。
因此,nums 中所有元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21 。
<strong>解释:</strong>nums 中共有 3 个特殊元素:nums[1],因为 4 被 1 整除;nums[2],因为 4 被 2 整除;以及 nums[4],因为 4 被 4 整除。
因此,nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21 。
</pre>

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

<pre><strong>输入:</strong>nums = [2,7,1,19,18,3]
<pre>
<strong>输入:</strong>nums = [2,7,1,19,18,3]
<strong>输出:</strong>63
<strong>解释:</strong>nums 中共有 4 个特殊元素:nums[1] ,因为 6 被 1 整除;nums[2] ,因为 6 被 2 整除;nums[3] ,因为 6 被 3 整除;以及 nums[6] ,因为 6 被 6 整除。
因此,nums 中所有元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63 。 </pre>
<strong>解释:</strong>nums 中共有 4 个特殊元素:nums[1],因为 6 被 1 整除;nums[2] ,因为 6 被 2 整除;nums[3],因为 6 被 3 整除;以及 nums[6],因为 6 被 6 整除。
因此,nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63 。 </pre>

<p>&nbsp;</p>

Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
<p>你可以执行下述 <strong>递增</strong> 运算 <strong>任意</strong> 次(可以是 <strong>0</strong> 次):</p>

<ul>
<li>从范围&nbsp;<code>[0, n - 1]</code> 中选则一个下标 <code>i</code> ,并将 <code>nums[i]</code> 的值加 <code>1</code> 。</li>
<li>从范围&nbsp;<code>[0, n - 1]</code> 中选择一个下标 <code>i</code> ,并将 <code>nums[i]</code> 的值加 <code>1</code> 。</li>
</ul>

<p>如果数组中任何长度 <strong>大于或等于 3</strong> 的子数组,其 <strong>最大</strong> 元素都大于或等于 <code>k</code> ,则认为数组是一个 <strong>美丽数组</strong> 。</p>
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

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

<p>节点 <code>0</code> 处现有一棵由 <code>n</code> 个节点组成的无向树,节点编号从 <code>0</code> 到 <code>n - 1</code> 。给你一个长度为 <code>n - 1</code> 的二维 <strong>整数</strong> 数组 <code>edges</code> ,其中 <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> 表示在树上的节点 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code> 之间存在一条边。另给你一个下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的数组 <code>coins</code> 和一个整数 <code>k</code> ,其中 <code>coins[i]</code> 表示节点 <code>i</code> 处的金币数量。</p>
<p>有一棵由 <code>n</code> 个节点组成的无向树,以&nbsp;<code>0</code>&nbsp; 为根节点,节点编号从 <code>0</code> 到 <code>n - 1</code> 。给你一个长度为 <code>n - 1</code> 的二维 <strong>整数</strong> 数组 <code>edges</code> ,其中 <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> 表示在树上的节点 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code> 之间存在一条边。另给你一个下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的数组 <code>coins</code> 和一个整数 <code>k</code> ,其中 <code>coins[i]</code> 表示节点 <code>i</code> 处的金币数量。</p>

<p>从根节点开始,你必须收集所有金币。要想收集节点上的金币,必须先收集该节点的祖先节点上的金币。</p>

@@ -22,7 +22,7 @@
<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/ex1-copy.png" style="width: 60px; height: 316px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/images/ex1-copy.png" style="width: 60px; height: 316px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
<pre>
<strong>输入:</strong>edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
<strong>输出:</strong>11
@@ -35,7 +35,7 @@
</pre>

<p><strong class="example">示例 2:</strong></p>
<strong class="example"> <img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/ex2.png" style="width: 140px; height: 147px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong>
<strong class="example"> <img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/images/ex2.png" style="width: 140px; height: 147px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong>

<pre>
<strong>输入:</strong>edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
Loading