Skip to content

Commit

Permalink
feat: update lc problems (#3438)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme authored Aug 21, 2024
1 parent 547f88c commit b098694
Show file tree
Hide file tree
Showing 51 changed files with 583 additions and 116 deletions.
6 changes: 3 additions & 3 deletions solution/0100-0199/0147.Insertion Sort List/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ tags:

<p>对链表进行插入排序。</p>

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/Insertion-sort-example-300px.gif" /></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/1724130387-qxfMwx-Insertion-sort-example-300px.gif" /></p>

<p>&nbsp;</p>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/sort1linked-list.jpg" /></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/1724130414-QbPAjl-image.png" /></p>

<pre>
<strong>输入:</strong> head = [4,2,1,3]
<strong>输出:</strong> [1,2,3,4]</pre>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/sort2linked-list.jpg" /></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/1724130432-zoOvdI-image.png" /></p>

<pre>
<strong>输入:</strong> head = [-1,5,3,4,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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions solution/0200-0299/0208.Implement Trie (Prefix Tree)/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ tags:

<!-- description:start -->

<p><strong><a href="https://baike.baidu.com/item/字典树/9825209?fr=aladdin" target="_blank">Trie</a></strong>(发音类似 "try")或者说 <strong>前缀树</strong> 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。</p>
<p><strong><a href="https://baike.baidu.com/item/字典树/9825209?fr=aladdin" target="_blank">Trie</a></strong>(发音类似 "try")或者说 <strong>前缀树</strong> 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补全和拼写检查。</p>

<p>请你实现 Trie 类:</p>

<ul>
<li><code>Trie()</code> 初始化前缀树对象。</li>
<li><code>void insert(String word)</code> 向前缀树中插入字符串 <code>word</code> 。</li>
<li><code>boolean search(String word)</code> 如果字符串 <code>word</code> 在前缀树中,返回 <code>true</code>(即,在检索之前已经插入);否则,返回 <code>false</code> 。</li>
<li><code>boolean startsWith(String prefix)</code> 如果之前已经插入的字符串 <code>word</code> 的前缀之一为 <code>prefix</code> ,返回 <code>true</code> ;否则,返回 <code>false</code> 。</li>
<li><code>boolean startsWith(String prefix)</code> 如果之前已经插入的字符串&nbsp;<code>word</code> 的前缀之一为 <code>prefix</code> ,返回 <code>true</code> ;否则,返回 <code>false</code> 。</li>
</ul>

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

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

Expand All @@ -51,12 +51,12 @@ trie.insert("app");
trie.search("app"); // 返回 True
</pre>

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

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

<ul>
<li><code>1 <= word.length, prefix.length <= 2000</code></li>
<li><code>1 &lt;= word.length, prefix.length &lt;= 2000</code></li>
<li><code>word</code> 和 <code>prefix</code> 仅由小写英文字母组成</li>
<li><code>insert</code>、<code>search</code> 和 <code>startsWith</code> 调用次数 <strong>总计</strong> 不超过 <code>3 * 10<sup>4</sup></code> 次</li>
</ul>
Expand Down
62 changes: 29 additions & 33 deletions solution/0300-0399/0379.Design Phone Directory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,47 @@ tags:

<!-- description:start -->

<p>设计一个电话目录管理系统,让它支持以下功能:</p>
<p>设计一个电话目录管理系统,一开始有&nbsp;<code>maxNumbers</code>&nbsp;个位置能够储存号码。系统应该存储号码,检查某个位置是否为空,并清空给定的位置。</p>

<ol>
<li><code>get</code>: 分配给用户一个未被使用的电话号码,获取失败请返回 -1</li>
<li><code>check</code>: 检查指定的电话号码是否被使用</li>
<li><code>release</code>: 释放掉一个电话号码,使其能够重新被分配</li>
</ol>
<p>实现&nbsp;<code>PhoneDirectory</code>&nbsp;类:</p>

<p>&nbsp;</p>

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

<pre>// 初始化电话目录,包括 3 个电话号码:0,1 和 2。
PhoneDirectory directory = new PhoneDirectory(3);

// 可以返回任意未分配的号码,这里我们假设它返回 0。
directory.get();

// 假设,函数返回 1。
directory.get();

// 号码 2 未分配,所以返回为 true。
directory.check(2);

// 返回 2,分配后,只剩一个号码未被分配。
directory.get();

// 此时,号码 2 已经被分配,所以返回 false。
directory.check(2);
<ul>
<li><code>PhoneDirectory(int maxNumbers)</code>&nbsp;电话目录初始有 <code>maxNumbers</code> 个可用位置。</li>
<li><code>int get()</code> 提供一个未分配给任何人的号码。如果没有可用号码则返回&nbsp;<code>-1</code>。</li>
<li><code>bool check(int number)</code>&nbsp;如果位置&nbsp;<code>number</code>&nbsp;可用返回 <code>true</code>&nbsp;否则返回&nbsp;<code>false</code>。</li>
<li><code>void release(int number)</code> 回收或释放位置&nbsp;<code>number</code>。</li>
</ul>

// 释放号码 2,将该号码变回未分配状态。
directory.release(2);
<p>&nbsp;</p>

// 号码 2 现在是未分配状态,所以返回 true。
directory.check(2);
<p><strong class="example">示例 1:</strong></p>

<pre>
<strong>输入:</strong>
["PhoneDirectory", "get", "get", "check", "get", "check", "release", "check"]
[[3], [], [], [2], [], [2], [2], [2]]
<strong>输出:</strong>
[null, 0, 1, true, 2, false, null, true]

<strong>解释:</strong>
PhoneDirectory phoneDirectory = new PhoneDirectory(3);
phoneDirectory.get(); // 它可以返回任意可用的数字。这里我们假设它返回 0。
phoneDirectory.get(); // 假设它返回 1。
phoneDirectory.check(2); // 数字 2 可用,所以返回 true。
phoneDirectory.get(); // 返回剩下的唯一一个数字 2。
phoneDirectory.check(2); // 数字 2 不再可用,所以返回 false。
phoneDirectory.release(2); // 将数字 2 释放回号码池。
phoneDirectory.check(2); // 数字 2 重新可用,返回 true。
</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;=&nbsp;maxNumbers &lt;= 10^4</code></li>
<li><code>1 &lt;= maxNumbers &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= number &lt; maxNumbers</code></li>
<li>调用方法的总数处于区间 <code>[0 - 20000]</code> 之内</li>
<li><code>get</code>,<code>check</code>&nbsp;和&nbsp;<code>release</code>&nbsp;最多被调用&nbsp;<code>2 * 10<sup>4</sup></code>&nbsp;次。</li>
</ul>

<!-- description:end -->
Expand Down
3 changes: 2 additions & 1 deletion solution/0300-0399/0391.Perfect Rectangle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ tags:
<ul>
<li><code>1 &lt;= rectangles.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>rectangles[i].length == 4</code></li>
<li><code>-10<sup>5</sup> &lt;= x<sub>i</sub>, y<sub>i</sub>, a<sub>i</sub>, b<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= x<sub>i</sub> &lt; a<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= y<sub>i</sub> &lt; b<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
</ul>

<!-- description:end -->
Expand Down
3 changes: 2 additions & 1 deletion solution/0300-0399/0391.Perfect Rectangle/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ tags:
<ul>
<li><code>1 &lt;= rectangles.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>rectangles[i].length == 4</code></li>
<li><code>-10<sup>5</sup> &lt;= x<sub>i</sub>, y<sub>i</sub>, a<sub>i</sub>, b<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= x<sub>i</sub> &lt; a<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= y<sub>i</sub> &lt; b<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
</ul>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Since now the four &lt;b&gt;&#39;s are consecutive, we merge them: &quot;&lt;b&g
</ul>

<p>&nbsp;</p>
<p><strong>Note:</strong> This question is the same as 758: <a href="https://leetcode.com/problems/bold-words-in-string/" target="_blank">https://leetcode.com/problems/bold-words-in-string/</a></p>
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/bold-words-in-string/description/" target="_blank">758. Bold Words in String</a>.</p>

<!-- description:end -->

Expand Down
10 changes: 5 additions & 5 deletions solution/0700-0799/0756.Pyramid Transition Matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ tags:
<li>例如,<code>"ABC"</code>&nbsp;表示一个三角形图案,其中一个 <code>“C”</code> 块堆叠在一个&nbsp;<code>'A'</code>&nbsp;块(左)和一个&nbsp;<code>'B'</code>&nbsp;块(右)之上。请注意,这与 <code>"BAC"</code>&nbsp;不同,<code>"B"</code>&nbsp;在左下角,<code>"A"</code>&nbsp;在右下角。</li>
</ul>

<p>你从底部的一排积木&nbsp;<code>bottom</code>&nbsp;开始,作为一个单一的字符串,你 <strong>必须</strong> 使用作为金字塔的底部。</p>
<p>你从作为单个字符串给出的底部的一排积木&nbsp;<code>bottom</code>&nbsp;开始,<strong>必须</strong>&nbsp;将其作为金字塔的底部。</p>

<p>在给定&nbsp;<code>bottom</code>&nbsp;&nbsp;<code>allowed</code>&nbsp;的情况下,如果你能一直构建到金字塔顶部,使金字塔中的 <strong>每个三角形图案</strong> 都是允许的,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
<p>在给定&nbsp;<code>bottom</code>&nbsp;&nbsp;<code>allowed</code>&nbsp;的情况下,如果你能一直构建到金字塔顶部,使金字塔中的 <strong>每个三角形图案</strong> 都是在&nbsp;<code>allowed</code>&nbsp;中的,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>

<p>&nbsp;</p>

Expand All @@ -39,7 +39,7 @@ tags:
<pre>
<strong>输入:</strong>bottom = "BCD", allowed = ["BCC","CDE","CEA","FFF"]
<strong>输出:</strong>true
<strong>解释:</strong>允许的三角形模式显示在右边
<strong>解释:</strong>允许的三角形图案显示在右边
从最底层(第 3 层)开始,我们可以在第 2 层构建“CE”,然后在第 1 层构建“E”。
金字塔中有三种三角形图案,分别是 “BCC”、“CDE” 和 “CEA”。都是允许的。
</pre>
Expand All @@ -51,8 +51,8 @@ tags:
<pre>
<strong>输入:</strong>bottom = "AAAA", allowed = ["AAB","AAC","BCD","BBE","DEF"]
<strong>输出:</strong>false
<strong>解释:</strong>允许的三角形模式显示在右边
从最底层(游戏邦注:即第 4 个关卡)开始,创造第 3 个关卡有多种方法,但如果尝试所有可能性,你便会在创造第 1 个关卡前陷入困境
<strong>解释:</strong>允许的三角形图案显示在右边
从最底层(即第 4 )开始,创造第 3 层有多种方法,但如果尝试所有可能性,你便会在创造第 1 层前陷入困境
</pre>

<p>&nbsp;</p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0700-0799/0758.Bold Words in String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tags:
</ul>

<p>&nbsp;</p>
<p><strong>Note:</strong> This question is the same as 616: <a href="https://leetcode.com/problems/add-bold-tag-in-string/" target="_blank">https://leetcode.com/problems/add-bold-tag-in-string/</a></p>
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/add-bold-tag-in-string/description/" target="_blank">616. Add Bold Tag in String</a>.</p>

<!-- description:end -->

Expand Down
12 changes: 6 additions & 6 deletions solution/1300-1399/1380.Lucky Numbers in a Matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tags:

<!-- description:start -->

<p>给你一个 <code>m * n</code> 的矩阵,矩阵中的数字 <strong>各不相同</strong> 。请你按 <strong>任意</strong> 顺序返回矩阵中的所有幸运数。</p>
<p>给你一个 <code>m x&nbsp;n</code> 的矩阵,矩阵中的数字 <strong>各不相同</strong> 。请你按 <strong>任意</strong> 顺序返回矩阵中的所有幸运数。</p>

<p><strong>幸运数</strong> 是指矩阵中满足同时下列两个条件的元素:</p>

Expand All @@ -30,28 +30,28 @@ tags:

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong>matrix = [[3,7,8],[9,11,13],[15,16,17]]
<strong>输出:</strong>[15]
<strong>解释:</strong>15 是唯一的幸运数,因为它是其所在行中的最小值,也是所在列中的最大值。
</pre>

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

<pre>
<strong>输入:</strong>matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
<strong>输出:</strong>[12]
<strong>解释:</strong>12 是唯一的幸运数,因为它是其所在行中的最小值,也是所在列中的最大值。
</pre>

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

<pre>
<strong>输入:</strong>matrix = [[7,8],[1,2]]
<strong>输出:</strong>[7]
<strong>解释:</strong>7是唯一的幸运数字,因为它是行中的最小值,列中的最大值。
<strong>解释:</strong>7 是唯一的幸运数字,因为它是行中的最小值,列中的最大值。
</pre>

<p>&nbsp;</p>
Expand All @@ -62,7 +62,7 @@ tags:
<li><code>m == mat.length</code></li>
<li><code>n == mat[i].length</code></li>
<li><code>1 &lt;= n, m &lt;= 50</code></li>
<li><code>1 &lt;=&nbsp;matrix[i][j]&nbsp;&lt;= 10^5</code></li>
<li><code>1 &lt;=&nbsp;matrix[i][j]&nbsp;&lt;= 10<sup>5</sup></code></li>
<li>矩阵中的所有元素都是不同的</li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source: 第 250 场周赛 Q3
tags:
- 数组
- 动态规划
- 矩阵
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source: Weekly Contest 250 Q3
tags:
- Array
- Dynamic Programming
- Matrix
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source: 第 273 场周赛 Q4
tags:
- 数组
- 哈希表
- 双指针
- 枚举
- 排序
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source: Weekly Contest 273 Q4
tags:
- Array
- Hash Table
- Two Pointers
- Enumeration
- Sorting
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ User 101:
- Spent 7 * 15 = 105 on product 3.
User 101 spent the most money on product 3.
User 102:
- Spent (9 + 7) * 10 = 150 on product 1.
- Spent (9 + 6) * 10 = 150 on product 1.
- Spent 6 * 25 = 150 on product 2.
- Spent 10 * 15 = 150 on product 3.
User 102 spent the most money on products 1, 2, and 3.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README.md
tags:
-
- 数组
- 哈希表
- 排序
- 单调栈
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README_EN.md
tags:
- Stack
- Array
- Hash Table
- Sorting
- Monotonic Stack
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md
tags:
- 位运算
- 递归
- 数组
- 动态规划
- 回溯
- 状态压缩
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README_EN.md
tags:
- Bit Manipulation
- Recursion
- Array
- Dynamic Programming
- Backtracking
- Bitmask
---

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

<p>给你两个长度相同的正整数数组 <code>nums</code> 和 <code>target</code>。</p>

<p>在一次操作中,你可以选择 <code>nums</code> 的任何<span data-keyword="subarray">子数组</span>,并将该子数组内的每个元素的值增加或减少 1。</p>
<p>在一次操作中,你可以选择 <code>nums</code> 的任何子数组,并将该子数组内的每个元素的值增加或减少 1。</p>

<p>返回使 <code>nums</code> 数组变为 <code>target</code> 数组所需的 <strong>最少 </strong>操作次数。</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tags:
<p><strong>提示:</strong></p>

<ul>
<li><code>1 &lt;= nums.lnegth &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tags:
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= nums.lnegth &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

Expand Down
Loading

0 comments on commit b098694

Please sign in to comment.