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

feat: update lc problems #3763

Merged
merged 1 commit into from
Nov 15, 2024
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
6 changes: 3 additions & 3 deletions lcp/LCP 12. 小张刷题计划/README.md
Original file line number Diff line number Diff line change
@@ -224,7 +224,7 @@ class Solution {
func minTime(_ time: [Int], _ m: Int) -> Int {
var left = 0
var right = time.reduce(0, +)

while left < right {
let mid = (left + right) / 2
if check(mid, time, m) {
@@ -235,12 +235,12 @@ class Solution {
}
return left
}

private func check(_ t: Int, _ time: [Int], _ m: Int) -> Bool {
var sum = 0
var maxTime = 0
var days = 1

for x in time {
sum += x
maxTime = max(maxTime, x)
1 change: 1 addition & 0 deletions solution/0300-0399/0384.Shuffle an Array/README.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0300-0399/0384.Shuffle%20an%20Array/README.md
tags:
- 设计
- 数组
- 数学
- 随机化
1 change: 1 addition & 0 deletions solution/0300-0399/0384.Shuffle an Array/README_EN.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md
tags:
- Design
- Array
- Math
- Randomized
12 changes: 6 additions & 6 deletions solution/0400-0499/0490.The Maze/README.md
Original file line number Diff line number Diff line change
@@ -28,14 +28,14 @@ tags:

<p>你可以 <strong>假定迷宫的边缘都是墙壁</strong>(参考示例)。</p>

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

<p><strong>示例 1:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0490.The%20Maze/images/maze1-1-grid.jpg" style="width: 573px; height: 573px;" />
<pre>
<strong>输入:</strong>maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]
<strong>输出:</strong>true
<strong>解释:</strong>一种可能的路径是 : 左 -> 下 -> 左 -> 下 -> 右 -> 下 -> 右。
<strong>解释:</strong>一种可能的路径是 : 左 -&gt; 下 -&gt; 左 -&gt; 下 -&gt; 右 -&gt; 下 -&gt; 右。
</pre>

<p><strong>示例 2:</strong></p>
@@ -53,19 +53,19 @@ tags:
<strong>输出:</strong>false
</pre>

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

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

<ul>
<li><code>m == maze.length</code></li>
<li><code>n == maze[i].length</code></li>
<li><code>1 <= m, n <= 100</code></li>
<li><code>1 &lt;= m, n &lt;= 100</code></li>
<li><code>maze[i][j]</code> is <code>0</code> or <code>1</code>.</li>
<li><code>start.length == 2</code></li>
<li><code>destination.length == 2</code></li>
<li><code>0 <= start<sub>row</sub>, destination<sub>row</sub> <= m</code></li>
<li><code>0 <= start<sub>col</sub>, destination<sub>col</sub> <= n</code></li>
<li><code>0 &lt;= start<sub>row</sub>, destination<sub>row</sub> &lt;&nbsp;m</code></li>
<li><code>0 &lt;= start<sub>col</sub>, destination<sub>col</sub> &lt;&nbsp;n</code></li>
<li>球和目的地都在空地上,且初始时它们不在同一位置</li>
<li>迷宫 <strong>至少包括 2 块空地</strong></li>
</ul>
4 changes: 2 additions & 2 deletions solution/0400-0499/0490.The Maze/README_EN.md
Original file line number Diff line number Diff line change
@@ -59,8 +59,8 @@ tags:
<li><code>maze[i][j]</code> is <code>0</code> or <code>1</code>.</li>
<li><code>start.length == 2</code></li>
<li><code>destination.length == 2</code></li>
<li><code>0 &lt;= start<sub>row</sub>, destination<sub>row</sub> &lt;= m</code></li>
<li><code>0 &lt;= start<sub>col</sub>, destination<sub>col</sub> &lt;= n</code></li>
<li><code>0 &lt;= start<sub>row</sub>, destination<sub>row</sub> &lt; m</code></li>
<li><code>0 &lt;= start<sub>col</sub>, destination<sub>col</sub> &lt; n</code></li>
<li>Both the ball and the destination exist in an empty space, and they will not be in the same position initially.</li>
<li>The maze contains <strong>at least 2 empty spaces</strong>.</li>
</ul>
43 changes: 26 additions & 17 deletions solution/0500-0599/0500.Keyboard Row/README.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ tags:

<p>给你一个字符串数组 <code>words</code> ,只返回可以使用在 <strong>美式键盘</strong> 同一行的字母打印出来的单词。键盘如下图所示。</p>

<p><strong>请注意</strong>,字符串&nbsp;<strong>不区分大小写</strong>,相同字母的大小写形式都被视为在同一行<strong>。</strong></p>

<p><strong>美式键盘</strong> 中:</p>

<ul>
@@ -30,36 +32,43 @@ tags:

<p><img alt="American keyboard" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0500.Keyboard%20Row/images/keyboard.png" style="width: 100%; max-width: 600px" /></p>

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

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

<pre>
<strong>输入:</strong>words = ["Hello","Alaska","Dad","Peace"]
<strong>输出:</strong>["Alaska","Dad"]
</pre>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">words = ["Hello","Alaska","Dad","Peace"]</span></p>

<p><b>输出:</b><span class="example-io">["Alaska","Dad"]</span></p>

<p><strong>解释:</strong></p>

<p>由于不区分大小写,<code>"a"</code> 和&nbsp;<code>"A"</code> 都在美式键盘的第二行。</p>
</div>

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

<pre>
<strong>输入:</strong>words = ["omk"]
<strong>输出:</strong>[]
</pre>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>words = ["omk"]</span></p>

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

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

<p><strong>示例 3:</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b></span><span class="example-io">words = ["adsdf","sfd"]</span></p>

<pre>
<strong>输入:</strong>words = ["adsdf","sfd"]
<strong>输出:</strong>["adsdf","sfd"]
</pre>
<p><span class="example-io"><b>输出:</b></span><span class="example-io">["adsdf","sfd"]</span></p>
</div>

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

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

<ul>
<li><code>1 <= words.length <= 20</code></li>
<li><code>1 <= words[i].length <= 100</code></li>
<li><code>1 &lt;= words.length &lt;= 20</code></li>
<li><code>1 &lt;= words[i].length &lt;= 100</code></li>
<li><code>words[i]</code> 由英文字母(小写和大写字母)组成</li>
</ul>

33 changes: 21 additions & 12 deletions solution/0500-0599/0500.Keyboard Row/README_EN.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ tags:

<p>Given an array of strings <code>words</code>, return <em>the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below</em>.</p>

<p><strong>Note</strong> that the strings are <strong>case-insensitive</strong>, both lowercased and uppercased of the same letter are treated as if they are at the same row.</p>

<p>In the <strong>American keyboard</strong>:</p>

<ul>
@@ -31,24 +33,31 @@ tags:
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> words = [&quot;Hello&quot;,&quot;Alaska&quot;,&quot;Dad&quot;,&quot;Peace&quot;]
<strong>Output:</strong> [&quot;Alaska&quot;,&quot;Dad&quot;]
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">words = [&quot;Hello&quot;,&quot;Alaska&quot;,&quot;Dad&quot;,&quot;Peace&quot;]</span></p>

<p><strong>Output:</strong> <span class="example-io">[&quot;Alaska&quot;,&quot;Dad&quot;]</span></p>

<p><strong>Explanation:</strong></p>

<p>Both <code>&quot;a&quot;</code> and <code>&quot;A&quot;</code> are in the 2nd row of the American keyboard due to case insensitivity.</p>
</div>

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

<pre>
<strong>Input:</strong> words = [&quot;omk&quot;]
<strong>Output:</strong> []
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">words = [&quot;omk&quot;]</span></p>

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

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

<pre>
<strong>Input:</strong> words = [&quot;adsdf&quot;,&quot;sfd&quot;]
<strong>Output:</strong> [&quot;adsdf&quot;,&quot;sfd&quot;]
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">words = [&quot;adsdf&quot;,&quot;sfd&quot;]</span></p>

<p><strong>Output:</strong> <span class="example-io">[&quot;adsdf&quot;,&quot;sfd&quot;]</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
14 changes: 7 additions & 7 deletions solution/0700-0799/0777.Swap Adjacent in LR String/README.md
Original file line number Diff line number Diff line change
@@ -9,24 +9,24 @@ tags:

<!-- problem:start -->

# [777. 在LR字符串中交换相邻字符](https://leetcode.cn/problems/swap-adjacent-in-lr-string)
# [777. 在 LR 字符串中交换相邻字符](https://leetcode.cn/problems/swap-adjacent-in-lr-string)

[English Version](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README_EN.md)

## 题目描述

<!-- description:start -->

<p>在一个由 <code>'L'</code> , <code>'R'</code> 和 <code>'X'</code> 三个字符组成的字符串(例如<code>"RXXLRXRXL"</code>)中进行移动操作。一次移动操作指用一个&nbsp;<code>"LX"</code>&nbsp;替换一个&nbsp;<code>"XL"</code>,或者用一个&nbsp;<code>"XR"</code>&nbsp;替换一个&nbsp;<code>"RX"</code>。现给定起始字符串&nbsp;<code>start</code>&nbsp;和结束字符串&nbsp;<code>end</code>,请编写代码,当且仅当存在一系列移动操作使得&nbsp;<code>start</code>&nbsp;可以转换成&nbsp;<code>end</code>&nbsp;时, 返回&nbsp;<code>True</code>。</p>
<p>在一个由 <code>'L'</code> , <code>'R'</code> 和 <code>'X'</code> 三个字符组成的字符串(例如<code>"RXXLRXRXL"</code>)中进行移动操作。一次移动操作指用一个&nbsp;<code>"LX"</code>&nbsp;替换一个&nbsp;<code>"XL"</code>,或者用一个&nbsp;<code>"XR"</code>&nbsp;替换一个&nbsp;<code>"RX"</code>。现给定起始字符串&nbsp;<code>start</code>&nbsp;和结束字符串&nbsp;<code>result</code>,请编写代码,当且仅当存在一系列移动操作使得&nbsp;<code>start</code>&nbsp;可以转换成&nbsp;<code>result</code>&nbsp;时, 返回&nbsp;<code>True</code>。</p>

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong>start = "RXXLRXRXL", end = "XRLXXRRLX"
<strong>输入:</strong>start = "RXXLRXRXL", result = "XRLXXRRLX"
<strong>输出:</strong>true
<strong>解释:</strong>通过以下步骤我们可以将 start 转化为 end
<strong>解释:</strong>通过以下步骤我们可以将 start 转化为 result
RXXLRXRXL -&gt;
XRXLRXRXL -&gt;
XRLXRXRXL -&gt;
@@ -37,7 +37,7 @@ XRLXXRRLX
<p><strong class="example">示例 2:</strong></p>

<pre>
<strong>输入:</strong>start = "X", end = "L"
<strong>输入:</strong>start = "X", result = "L"
<strong>输出:</strong>false
</pre>

@@ -47,8 +47,8 @@ XRLXXRRLX

<ul>
<li><code>1 &lt;= start.length&nbsp;&lt;= 10<sup>4</sup></code></li>
<li><code>start.length == end.length</code></li>
<li><code>start</code> 和&nbsp;<code>end</code>&nbsp;都只包含&nbsp;<code>'L'</code>, <code>'R'</code>&nbsp;或&nbsp;<code>'X'</code>。</li>
<li><code>start.length == result.length</code></li>
<li><code>start</code> 和&nbsp;<code>result</code>&nbsp;都只包含&nbsp;<code>'L'</code>, <code>'R'</code>&nbsp;或&nbsp;<code>'X'</code>。</li>
</ul>

<!-- description:end -->
4 changes: 2 additions & 2 deletions solution/0900-0999/0909.Snakes and Ladders/README.md
Original file line number Diff line number Diff line change
@@ -36,13 +36,13 @@ tags:

<p>如果 <code>board[r][c] != -1</code>&nbsp;,位于&nbsp;<code>r</code> 行 <code>c</code> 列的棋盘格中可能存在 “蛇” 或 “梯子”。那个蛇或梯子的目的地将会是 <code>board[r][c]</code>。编号为 <code>1</code> 和 <code>n<sup>2</sup></code> 的方格不是任何蛇或梯子的起点。</p>

<p>注意,玩家在每回合的前进过程中最多只能爬过蛇或梯子一次:就算目的地是另一条蛇或梯子的起点,玩家也 <strong>不能</strong> 继续移动。</p>
<p>注意,玩家在每次掷骰的前进过程中最多只能爬过蛇或梯子一次:就算目的地是另一条蛇或梯子的起点,玩家也 <strong>不能</strong> 继续移动。</p>

<ul>
<li>举个例子,假设棋盘是 <code>[[-1,4],[-1,3]]</code> ,第一次移动,玩家的目标方格是 <code>2</code> 。那么这个玩家将会顺着梯子到达方格 <code>3</code> ,但 <strong>不能</strong> 顺着方格 <code>3</code> 上的梯子前往方格 <code>4</code> 。(简单来说,类似飞行棋,玩家掷出骰子点数后移动对应格数,遇到单向的路径(即梯子或蛇)可以直接跳到路径的终点,但如果多个路径首尾相连,也不能连续跳多个路径)</li>
</ul>

<p>返回达到编号为&nbsp;<code>n<sup>2</sup></code> 的方格所需的最少移动次数,如果不可能,则返回 <code>-1</code>。</p>
<p>返回达到编号为&nbsp;<code>n<sup>2</sup></code> 的方格所需的最少掷骰次数,如果不可能,则返回 <code>-1</code>。</p>

<p>&nbsp;</p>

8 changes: 4 additions & 4 deletions solution/1000-1099/1095.Find in Mountain Array/README.md
Original file line number Diff line number Diff line change
@@ -53,14 +53,14 @@ tags:
<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong>array = [1,2,3,4,5,3,1], target = 3
<strong>输入:</strong>mountainArr = [1,2,3,4,5,3,1], target = 3
<strong>输出:</strong>2
<strong>解释:</strong>3 在数组中出现了两次,下标分别为 2 和 5,我们返回最小的下标 2。</pre>

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

<pre>
<strong>输入:</strong>array = [0,1,2,4,2,1], target = 3
<strong>输入:</strong>mountainArr = [0,1,2,4,2,1], target = 3
<strong>输出:</strong>-1
<strong>解释:</strong>3 在数组中没有出现,返回 -1。
</pre>
@@ -70,9 +70,9 @@ tags:
<p><strong>提示:</strong></p>

<ul>
<li><code>3 &lt;= mountain_arr.length() &lt;= 10<sup>4</sup></code></li>
<li><code>3 &lt;= mountainArr.length() &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= target &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= mountain_arr.get(index) &lt;=&nbsp;10<sup>9</sup></code></li>
<li><code>0 &lt;= mountainArr.get(index) &lt;=&nbsp;10<sup>9</sup></code></li>
</ul>

<!-- description:end -->
8 changes: 4 additions & 4 deletions solution/1000-1099/1095.Find in Mountain Array/README_EN.md
Original file line number Diff line number Diff line change
@@ -49,14 +49,14 @@ tags:
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> array = [1,2,3,4,5,3,1], target = 3
<strong>Input:</strong> mountainArr = [1,2,3,4,5,3,1], target = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.</pre>

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

<pre>
<strong>Input:</strong> array = [0,1,2,4,2,1], target = 3
<strong>Input:</strong> mountainArr = [0,1,2,4,2,1], target = 3
<strong>Output:</strong> -1
<strong>Explanation:</strong> 3 does not exist in <code>the array,</code> so we return -1.
</pre>
@@ -65,9 +65,9 @@ tags:
<p><strong>Constraints:</strong></p>

<ul>
<li><code>3 &lt;= mountain_arr.length() &lt;= 10<sup>4</sup></code></li>
<li><code>3 &lt;= mountainArr.length() &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= target &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= mountain_arr.get(index) &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= mountainArr.get(index) &lt;= 10<sup>9</sup></code></li>
</ul>

<!-- description:end -->
36 changes: 23 additions & 13 deletions solution/1200-1299/1257.Smallest Common Region/README.md
Original file line number Diff line number Diff line change
@@ -25,38 +25,48 @@ tags:

<p>给你一些区域列表&nbsp;<code>regions</code> ,每个列表的第一个区域都包含这个列表内所有其他区域。</p>

<p>很自然地,如果区域&nbsp;<code>X</code> 包含区域&nbsp;<code>Y</code> ,那么区域&nbsp;<code>X</code> &nbsp;比区域&nbsp;<code>Y</code> 大。</p>
<p>很自然地,如果区域&nbsp;<code>x</code> 包含区域&nbsp;<code>y</code> ,那么区域&nbsp;<code>x</code> &nbsp;比区域&nbsp;<code>y</code> 大。同时根据定义,区域&nbsp;<code>x</code> 包含自身。</p>

<p>给定两个区域&nbsp;<code>region1</code>&nbsp;和&nbsp;<code>region2</code> ,找到同时包含这两个区域的&nbsp;<strong>最小&nbsp;</strong>区域。</p>

<p>如果区域列表中&nbsp;<code>r1</code>&nbsp;包含&nbsp;<code>r2</code>&nbsp;&nbsp;<code>r3</code> ,那么数据保证&nbsp;<code>r2</code> 不会包含&nbsp;<code>r3</code>&nbsp;。</p>
<p>如果给定区域&nbsp;<code>r1</code>,<code>r2</code>&nbsp;&nbsp;<code>r3</code>,使得&nbsp;<code>r1</code>&nbsp;包含&nbsp;<code>r3</code>,那么数据保证&nbsp;<code>r2</code> 不会包含&nbsp;<code>r3</code>&nbsp;。</p>

<p>数据同样保证最小公共区域一定存在。</p>
<p>数据同样保证最小区域一定存在。</p>

<p>&nbsp;</p>

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

<pre>
<strong>输入:
</strong>regions = [[&quot;Earth&quot;,&quot;North America&quot;,&quot;South America&quot;],
[&quot;North America&quot;,&quot;United States&quot;,&quot;Canada&quot;],
[&quot;United States&quot;,&quot;New York&quot;,&quot;Boston&quot;],
[&quot;Canada&quot;,&quot;Ontario&quot;,&quot;Quebec&quot;],
[&quot;South America&quot;,&quot;Brazil&quot;]],
region1 = &quot;Quebec&quot;,
region2 = &quot;New York&quot;
<strong>输出:</strong>&quot;North America&quot;
</strong>regions = [["Earth","North America","South America"],
["North America","United States","Canada"],
["United States","New York","Boston"],
["Canada","Ontario","Quebec"],
["South America","Brazil"]],
region1 = "Quebec",
region2 = "New York"
<strong>输出:</strong>"North America"
</pre>

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

<pre>
<b>输入:</b>regions = [["Earth", "North America", "South America"],["North America", "United States", "Canada"],["United States", "New York", "Boston"],["Canada", "Ontario", "Quebec"],["South America", "Brazil"]], region1 = "Canada", region2 = "South America"
<b>输出:</b>"Earth"
</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>2 &lt;= regions.length &lt;= 10^4</code></li>
<li><code>2 &lt;= regions.length &lt;= 10<sup>4</sup></code></li>
<li><code>2 &lt;= regions[i].length &lt;= 20</code></li>
<li><code>1 &lt;= regions[i][j].length, region1.length, region2.length &lt;= 20</code></li>
<li><code>region1 != region2</code></li>
<li>所有字符串只包含英文字母和空格,且最多只有&nbsp;20 个字母。</li>
<li><code>regions[i][j]</code>,<code>region1</code>&nbsp;和&nbsp;<code>region2</code> 由英语字母组成。</li>
<li>输入保证存在一个区域直接或间接包含所有其他区域。</li>
</ul>

<!-- description:end -->
Loading