Skip to content

feat: add new lc problems #1495

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
Aug 24, 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
2 changes: 1 addition & 1 deletion solution/0100-0199/0137.Single Number II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p>给你一个整数数组&nbsp;<code>nums</code> ,除某个元素仅出现 <strong>一次</strong> 外,其余每个元素都恰出现 <strong>三次 。</strong>请你找出并返回那个只出现了一次的元素。</p>

<p>你必须设计并实现线性时间复杂度的算法且不使用额外空间来解决此问题。</p>
<p>你必须设计并实现线性时间复杂度的算法且使用常数级空间来解决此问题。</p>

<p>&nbsp;</p>

Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0139.Word Break/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<li><code>1 &lt;= s.length &lt;= 300</code></li>
<li><code>1 &lt;= wordDict.length &lt;= 1000</code></li>
<li><code>1 &lt;= wordDict[i].length &lt;= 20</code></li>
<li><code>s</code> 和 <code>wordDict[i]</code> 仅有小写英文字母组成</li>
<li><code>s</code> 和 <code>wordDict[i]</code> 仅由小写英文字母组成</li>
<li><code>wordDict</code> 中的所有字符串 <strong>互不相同</strong></li>
</ul>

Expand Down
10 changes: 6 additions & 4 deletions solution/0100-0199/0175.Combine Two Tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
personId 是该表的主键列
personId 是该表的主键(具有唯一值的列)
该表包含一些人的 ID 和他们的姓和名的信息。
</pre>

Expand All @@ -33,15 +33,17 @@ personId 是该表的主键列。
| City | varchar |
| State | varchar |
+-------------+---------+
addressId 是该表的主键列
addressId 是该表的主键(具有唯一值的列)
该表的每一行都包含一个 ID = PersonId 的人的城市和州的信息。
</pre>

<p>编写一个SQL查询来报告 <code>Person</code> 表中每个人的姓、名、城市和州。如果 <code>personId</code> 的地址不在&nbsp;<code>Address</code>&nbsp;表中,则报告为空 &nbsp;<code>null</code>&nbsp;。</p>
<p>&nbsp;</p>

<p>编写解决方案,报告 <code>Person</code> 表中每个人的姓、名、城市和州。如果 <code>personId</code> 的地址不在&nbsp;<code>Address</code>&nbsp;表中,则报告为&nbsp;<code>null</code>&nbsp;。</p>

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

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

<p>&nbsp;</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
| salary | int |
| managerId | int |
+-------------+---------+
Id是该表的主键
id 是该表的主键(具有唯一值的列)
该表的每一行都表示雇员的ID、姓名、工资和经理的ID。
</pre>

<p>&nbsp;</p>

<p>编写一个SQL查询来查找收入比经理高的员工。</p>
<p>编写解决方案,找出收入比经理高的员工。</p>

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

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

<p>&nbsp;</p>

Expand Down
6 changes: 3 additions & 3 deletions solution/0100-0199/0182.Duplicate Emails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
| id | int |
| email | varchar |
+-------------+---------+
id 是该表的主键列
id 是该表的主键(具有唯一值的列)
此表的每一行都包含一封电子邮件。电子邮件不包含大写字母。
</pre>

<p>&nbsp;</p>

<p>编写一个 SQL 查询来报告所有重复的电子邮件。 请注意,可以保证电子邮件字段不为 NULL。</p>
<p>编写解决方案来报告所有重复的电子邮件。 请注意,可以保证电子邮件字段不为 NULL。</p>

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

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

<p>&nbsp;</p>

Expand Down
2 changes: 1 addition & 1 deletion solution/0400-0499/0401.Binary Watch/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<li>For example, <code>&quot;01:00&quot;</code> is not valid. It should be <code>&quot;1:00&quot;</code>.</li>
</ul>

<p>The minute must be consist of two digits and may contain a leading zero.</p>
<p>The minute must&nbsp;consist of two digits and may contain a leading zero.</p>

<ul>
<li>For example, <code>&quot;10:2&quot;</code> is not valid. It should be <code>&quot;10:02&quot;</code>.</li>
Expand Down
4 changes: 2 additions & 2 deletions solution/0500-0599/0529.Minesweeper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0529.Minesweeper/images/minesweeper_example_1.png" style="width: 500px; max-width: 400px; height: 269px;" />
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0529.Minesweeper/images/untitled.jpeg" style="width: 500px; max-width: 400px; height: 269px;" />
<pre>
<strong>输入:</strong>board = [["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]], click = [3,0]
<strong>输出:</strong>[["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]
</pre>

<p><strong>示例 2:</strong></p>
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0529.Minesweeper/images/minesweeper_example_2.png" style="width: 500px; max-width: 400px; height: 275px;" />
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0529.Minesweeper/images/untitled-2.jpeg" style="width: 500px; max-width: 400px; height: 275px;" />
<pre>
<strong>输入:</strong>board = [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]], click = [1,2]
<strong>输出:</strong>[["B","1","E","1","B"],["B","1","X","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]
Expand Down
19 changes: 13 additions & 6 deletions solution/0500-0599/0534.Game Play Analysis III/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

<p>Table:&nbsp;<code>Activity</code></p>
<p>表:<code>Activity</code></p>

<pre>
+--------------+---------+
Expand All @@ -17,18 +17,25 @@
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id,event_date)是此表的主键。
(player_id,event_date)是此表的主键(具有唯一值的列)
这张表显示了某些游戏的玩家的活动情况。
每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0 )。
</pre>

<p>&nbsp;</p>

<p>编写一个 SQL 查询,同时报告每组玩家和日期,以及玩家到目前为止玩了多少游戏。也就是说,在此日期之前玩家所玩的游戏总数。详细情况请查看示例。</p>
<p>编写一个解决方案,同时报告每组玩家和日期,以及玩家到 <strong>目前为止</strong> 玩了多少游戏。也就是说,玩家在该日期之前所玩的游戏总数。详细情况请查看示例。</p>

<p>查询结果格式如下所示:</p>
<p>以 <strong>任意顺序</strong> 返回结果表。</p>

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

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong>
Activity table:
+-----------+-----------+------------+--------------+
| player_id | device_id | event_date | games_played |
Expand All @@ -39,8 +46,7 @@ Activity table:
| 3 | 1 | 2016-03-02 | 0 |
| 3 | 4 | 2018-07-03 | 5 |
+-----------+-----------+------------+--------------+

Result table:
<strong>输出:</strong>
+-----------+------------+---------------------+
| player_id | event_date | games_played_so_far |
+-----------+------------+---------------------+
Expand All @@ -50,6 +56,7 @@ Result table:
| 3 | 2016-03-02 | 0 |
| 3 | 2018-07-03 | 5 |
+-----------+------------+---------------------+
<strong>解释:</strong>
对于 ID 为 1 的玩家,2016-05-02 共玩了 5+6=11 个游戏,2017-06-25 共玩了 5+6+1=12 个游戏。
对于 ID 为 3 的玩家,2018-07-03 共玩了 0+5=5 个游戏。
请注意,对于每个玩家,我们只关心玩家的登录日期。
Expand Down
21 changes: 14 additions & 7 deletions solution/0500-0599/0550.Game Play Analysis IV/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@

<p>Table:&nbsp;<code>Activity</code></p>

<pre>+--------------+---------+
<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| player_id | int |
| device_id | int |
| event_date | date |
| games_played | int |
+--------------+---------+
(player_id,event_date)是此表的主键。
(player_id,event_date)是此表的主键(具有唯一值的列的组合)
这张表显示了某些游戏的玩家的活动情况。
每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0)。
</pre>

<p>&nbsp;</p>

<p>编写一个 SQL 查询,报告在首次登录的第二天再次登录的玩家的比率,四舍五入到小数点后两位。换句话说,您需要计算从首次登录日期开始至少连续两天登录的玩家的数量,然后除以玩家总数。</p>
<p>编写解决方案,报告在首次登录的第二天再次登录的玩家的 <strong>比率</strong>,<strong>四舍五入到小数点后两位</strong>。换句话说,你需要计算从首次登录日期开始至少连续两天登录的玩家的数量,然后除以玩家总数。</p>

<p>结果格式如下所示:</p>

<p>查询结果格式如下所示:</p>
<p>&nbsp;</p>

<pre>Activity table:
<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong>
Activity table:
+-----------+-----------+------------+--------------+
| player_id | device_id | event_date | games_played |
+-----------+-----------+------------+--------------+
Expand All @@ -37,13 +44,13 @@
| 3 | 1 | 2016-03-02 | 0 |
| 3 | 4 | 2018-07-03 | 5 |
+-----------+-----------+------------+--------------+

Result table:
<strong>输出:</strong>
+-----------+
| fraction |
+-----------+
| 0.33 |
+-----------+
<strong>解释:</strong>
只有 ID 为 1 的玩家在第一天登录后才重新登录,所以答案是 1/3 = 0.33
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
| gender | varchar |
| dept_id | int |
+--------------+---------+
Student_id是该表的主键
student_id 是该表的主键(具有唯一值的列)
dept_id是Department表中dept_id的外键。
该表的每一行都表示学生的姓名、性别和所属系的id。
</pre>
Expand All @@ -33,16 +33,16 @@ dept_id是Department表中dept_id的外键。
| dept_id | int |
| dept_name | varchar |
+-------------+---------+
Dept_id是该表的主键
dept_id是该表的主键(具有唯一值的列)
该表的每一行包含一个部门的id和名称。</pre>

<p>&nbsp;</p>

<p>编写一个SQL查询,为&nbsp;<code>Department</code>&nbsp;表中的所有部门(甚至是没有当前学生的部门)报告各自的部门名称和每个部门的学生人数。</p>
<p>编写解决方案,为&nbsp;<code>Department</code>&nbsp;表中的所有部门(甚至是没有当前学生的部门)报告各自的部门名称和每个部门的学生人数。</p>

<p>按 <code>student_number</code> <strong>降序&nbsp;</strong>返回结果表。如果是平局,则按 <code>dept_name</code> 的&nbsp; <strong>字母顺序&nbsp;</strong>排序。</p>

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

<p>&nbsp;</p>

Expand Down
14 changes: 7 additions & 7 deletions solution/0500-0599/0582.Kill Process/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

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

<p>系统中存在 <code>n</code> 个进程,形成一个有根树结构。给你两个整数数组 <code>pid</code> 和 <code>ppid</code> ,其中 <code>pid[i]</code> 是第 <code>i</code> 个进程的 ID ,<code>ppid[i]</code> 是第 <code>i</code> 个进程的父进程 ID 。</p>
<p>系统中存在 <code>n</code>&nbsp;个进程,形成一个有根树结构。给你两个整数数组&nbsp;<code>pid</code> 和 <code>ppid</code> ,其中 <code>pid[i]</code> 是第 <code>i</code> 个进程的 ID ,<code>ppid[i]</code> 是第 <code>i</code> 个进程的父进程 ID 。</p>

<p>每一个进程只有 <strong>一个父进程</strong> ,但是可能会有 <strong>一个或者多个子进程</strong> 。只有一个进程的 <code>ppid[i] = 0</code> ,意味着这个进程 <strong>没有父进程</strong> 。</p>

<p>当一个进程 <strong>被杀掉</strong> 的时候,它所有的子进程和后代进程都要被杀掉。</p>

<p>给你一个整数 <code>kill</code> 表示要杀掉​​进程的 ID ,返回杀掉该进程后的所有进程 ID 的列表。可以按 <strong>任意顺序</strong> 返回答案。</p>
 
<p>给你一个整数 <code>kill</code> 表示要杀掉​​进程的 ID ,返回被杀掉的进程的 ID 列表。可以按 <strong>任意顺序</strong> 返回答案。</p>
&nbsp;

<p><strong>示例 1:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0582.Kill%20Process/images/ptree.jpg" style="width: 207px; height: 302px;" />
Expand All @@ -30,16 +30,16 @@
<strong>输出:</strong>[1]
</pre>

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

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

<ul>
<li><code>n == pid.length</code></li>
<li><code>n == ppid.length</code></li>
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
<li><code>1 <= pid[i] <= 5 * 10<sup>4</sup></code></li>
<li><code>0 <= ppid[i] <= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= pid[i] &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= ppid[i] &lt;= 5 * 10<sup>4</sup></code></li>
<li>仅有一个进程没有父进程</li>
<li><code>pid</code> 中的所有值 <strong>互不相同</strong></li>
<li>题目数据保证 <code>kill</code> 在 <code>pid</code> 中</li>
Expand Down
39 changes: 28 additions & 11 deletions solution/0600-0699/0620.Not Boring Movies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,36 @@

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

<p>某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 LED显示板做电影推荐,上面公布着影评和相关电影描述。</p>
<p>表:<code>cinema</code></p>

<p>作为该电影院的信息部主管,您需要编写一个 SQL查询,找出所有影片描述为<strong>非</strong>&nbsp;<code>boring</code>&nbsp;(不无聊)&nbsp;的并且<strong> id 为奇数&nbsp;</strong>的影片,结果请按等级 <code>rating</code> 排列。</p>
<pre>
+----------------+----------+
| Column Name | Type |
+----------------+----------+
| id | int |
| movie | varchar |
| description | varchar |
| rating | float |
+----------------+----------+
id 是该表的主键(具有唯一值的列)。
每行包含有关电影名称、类型和评级的信息。
评级为 [0,10] 范围内的小数点后 2 位浮点数。
</pre>

<p>&nbsp;</p>

<p>编写解决方案,找出所有影片描述为&nbsp;<strong>非</strong>&nbsp;<code>boring</code>&nbsp;(不无聊)&nbsp;的并且<strong> id 为奇数&nbsp;</strong>的影片。</p>

<p>返回结果按&nbsp;<code>rating</code>&nbsp;<strong>降序排列</strong>。</p>

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

<p>&nbsp;</p>

<p>例如,下表 <code>cinema</code>:</p>
<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong>
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
Expand All @@ -23,22 +44,18 @@
| 3 | irish | boring | 6.2 |
| 4 | Ice song | Fantacy | 8.6 |
| 5 | House card| Interesting| 9.1 |
+---------+-----------+--------------+-----------+
</pre>

<p>对于上面的例子,则正确的输出是为:</p>

<pre>
<strong>+---------+-----------+--------------+-----------+
输出:</strong>
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 5 | House card| Interesting| 9.1 |
| 1 | War | great 3D | 8.9 |
+---------+-----------+--------------+-----------+
<strong>解释:</strong>
我们有三部电影,它们的 id 是奇数:1、3 和 5。id = 3 的电影是 boring 的,所以我们不把它包括在答案中。
</pre>

<p>&nbsp;</p>

## 解法

<!-- 这里可写通用的实现逻辑 -->
Expand Down
6 changes: 3 additions & 3 deletions solution/0600-0699/0627.Swap Salary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
| sex | ENUM |
| salary | int |
+-------------+----------+
id 是这个表的主键。
id 是这个表的主键(具有唯一值的列)
sex 这一列的值是 ENUM 类型,只能从 ('m', 'f') 中取。
本表包含公司雇员的信息。
</pre>

<p>&nbsp;</p>

<p>请你编写一个 SQL 查询来交换所有的 <code>'f'</code> 和 <code>'m'</code> (即,将所有 <code>'f'</code> 变为 <code>'m'</code> ,反之亦然),仅使用 <strong>单个 update 语句</strong> ,且不产生中间临时表。</p>
<p>请你编写一个解决方案来交换所有的 <code>'f'</code> 和 <code>'m'</code> (即,将所有 <code>'f'</code> 变为 <code>'m'</code> ,反之亦然),仅使用 <strong>单个 update 语句</strong> ,且不产生中间临时表。</p>

<p>注意,你必须仅使用一条 update 语句,且 <strong>不能</strong> 使用 select 语句。</p>

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

<p>&nbsp;</p>

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

## Description

<p>Let&#39;s define a function <code>countUniqueChars(s)</code> that returns the number of unique characters on <code>s</code>.</p>
<p>Let&#39;s define a function <code>countUniqueChars(s)</code> that returns the number of unique characters in&nbsp;<code>s</code>.</p>

<ul>
<li>For example, calling <code>countUniqueChars(s)</code> if <code>s = &quot;LEETCODE&quot;</code> then <code>&quot;L&quot;</code>, <code>&quot;T&quot;</code>, <code>&quot;C&quot;</code>, <code>&quot;O&quot;</code>, <code>&quot;D&quot;</code> are the unique characters since they appear only once in <code>s</code>, therefore <code>countUniqueChars(s) = 5</code>.</li>
Expand Down
Loading