Skip to content

Commit 6f2245a

Browse files
committed
update
1 parent 8598592 commit 6f2245a

25 files changed

+13816
-11602
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 力扣题库(完整版)
22

3-
> 最后更新日期: **2022.08.26**
3+
> 最后更新日期: **2022.08.29**
44
>
55
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
66

leetcode-cn/origin-data.json

+6,930-6,825
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"data": {
3+
"question": {
4+
"questionId": "2523",
5+
"questionFrontendId": "2388",
6+
"categoryTitle": "Database",
7+
"boundTopicId": 1776356,
8+
"title": "Change Null Values in a Table to the Previous Value",
9+
"titleSlug": "change-null-values-in-a-table-to-the-previous-value",
10+
"content": null,
11+
"translatedTitle": null,
12+
"translatedContent": null,
13+
"isPaidOnly": true,
14+
"difficulty": "Medium",
15+
"likes": 0,
16+
"dislikes": 0,
17+
"isLiked": null,
18+
"similarQuestions": "[]",
19+
"contributors": [],
20+
"langToValidPlayground": null,
21+
"topicTags": [],
22+
"companyTagStats": null,
23+
"codeSnippets": null,
24+
"stats": "{\"totalAccepted\": \"24\", \"totalSubmission\": \"43\", \"totalAcceptedRaw\": 24, \"totalSubmissionRaw\": 43, \"acRate\": \"55.8%\"}",
25+
"hints": [],
26+
"solution": null,
27+
"status": null,
28+
"sampleTestCase": "{\"headers\": {\"CoffeeShop\": [\"id\", \"drink\"]}, \"rows\": {\"CoffeeShop\": [[9, \"Mezcal Margarita\"], [6, null], [7, null], [3, \"Americano\"], [1, \"Daiquiri\"], [2, null]]}}",
29+
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists CoffeeShop (id int, drink varchar(20))\"\n ],\n \"mssql\": [\n \"Create table CoffeeShop (id int, drink varchar(20))\"\n ],\n \"oraclesql\": [\n \"Create table CoffeeShop (id int, drink varchar(20))\"\n ],\n \"database\": true\n}",
30+
"judgerAvailable": true,
31+
"judgeType": "large",
32+
"mysqlSchemas": [
33+
"Create table If Not Exists CoffeeShop (id int, drink varchar(20))",
34+
"Truncate table CoffeeShop",
35+
"insert into CoffeeShop (id, drink) values ('9', 'Mezcal Margarita')",
36+
"insert into CoffeeShop (id, drink) values ('6', 'None')",
37+
"insert into CoffeeShop (id, drink) values ('7', 'None')",
38+
"insert into CoffeeShop (id, drink) values ('3', 'Americano')",
39+
"insert into CoffeeShop (id, drink) values ('1', 'Daiquiri')",
40+
"insert into CoffeeShop (id, drink) values ('2', 'None')"
41+
],
42+
"enableRunCode": true,
43+
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
44+
"book": null,
45+
"isSubscribed": false,
46+
"isDailyQuestion": false,
47+
"dailyRecordStatus": null,
48+
"editorType": "CKEDITOR",
49+
"ugcQuestionId": null,
50+
"style": "LEETCODE",
51+
"exampleTestcases": "{\"headers\": {\"CoffeeShop\": [\"id\", \"drink\"]}, \"rows\": {\"CoffeeShop\": [[9, \"Mezcal Margarita\"], [6, null], [7, null], [3, \"Americano\"], [1, \"Daiquiri\"], [2, null]]}}",
52+
"__typename": "QuestionNode"
53+
}
54+
}
55+
}

leetcode-cn/originData/build-a-matrix-with-conditions.json

+164
Large diffs are not rendered by default.

leetcode-cn/originData/longest-subsequence-with-limited-sum.json

+165
Large diffs are not rendered by default.

leetcode-cn/originData/minimum-amount-of-time-to-collect-garbage.json

+164
Large diffs are not rendered by default.

leetcode-cn/originData/removing-stars-from-a-string.json

+164
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<p>给你一个包含若干星号 <code>*</code> 的字符串 <code>s</code></p>
2+
3+
<p>在一步操作中,你可以:</p>
4+
5+
<ul>
6+
<li>选中 <code>s</code> 中的一个星号。</li>
7+
<li>移除星号 <strong>左侧</strong> 最近的那个 <strong>非星号</strong> 字符,并移除该星号自身。</li>
8+
</ul>
9+
10+
<p>返回移除 <strong>所有</strong> 星号之后的字符串<strong></strong></p>
11+
12+
<p><strong>注意:</strong></p>
13+
14+
<ul>
15+
<li>生成的输入保证总是可以执行题面中描述的操作。</li>
16+
<li>可以证明结果字符串是唯一的。</li>
17+
</ul>
18+
19+
<p>&nbsp;</p>
20+
21+
<p><strong>示例 1:</strong></p>
22+
23+
<pre>
24+
<strong>输入:</strong>s = "leet**cod*e"
25+
<strong>输出:</strong>"lecoe"
26+
<strong>解释:</strong>从左到右执行移除操作:
27+
- 距离第 1 个星号最近的字符是 "lee<em><strong>t</strong></em>**cod*e" 中的 't' ,s 变为 "lee*cod*e" 。
28+
- 距离第 2 个星号最近的字符是 "le<em><strong>e</strong></em>*cod*e" 中的 'e' ,s 变为 "lecod*e" 。
29+
- 距离第 3 个星号最近的字符是 "leco<em><strong>d</strong></em>*e" 中的 'd' ,s 变为 "lecoe" 。
30+
不存在其他星号,返回 "lecoe" 。</pre>
31+
32+
<p><strong>示例 2:</strong></p>
33+
34+
<pre>
35+
<strong>输入:</strong>s = "erase*****"
36+
<strong>输出:</strong>""
37+
<strong>解释:</strong>整个字符串都会被移除,所以返回空字符串。
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
42+
<p><strong>提示:</strong></p>
43+
44+
<ul>
45+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
46+
<li><code>s</code> 由小写英文字母和星号 <code>*</code> 组成</li>
47+
<li><code>s</code> 可以执行上述操作</li>
48+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<p>给你一个长度为 <code>n</code>&nbsp;的整数数组 <code>nums</code> ,和一个长度为 <code>m</code> 的整数数组 <code>queries</code></p>
2+
3+
<p>返回一个长度为 <code>m</code> 的数组<em> </em><code>answer</code><em> </em>,其中<em> </em><code>answer[i]</code><em> </em><code>nums</code><span style=""> </span>元素之和小于等于 <code>queries[i]</code><strong>子序列</strong><strong>最大</strong> 长度<span style="">&nbsp;</span><span style=""> </span></p>
4+
5+
<p><strong>子序列</strong> 是由一个数组删除某些元素(也可以不删除)但不改变剩余元素顺序得到的一个数组。</p>
6+
7+
<p>&nbsp;</p>
8+
9+
<p><strong>示例 1:</strong></p>
10+
11+
<pre>
12+
<strong>输入:</strong>nums = [4,5,2,1], queries = [3,10,21]
13+
<strong>输出:</strong>[2,3,4]
14+
<strong>解释:</strong>queries 对应的 answer 如下:
15+
- 子序列 [2,1] 的和小于或等于 3 。可以证明满足题目要求的子序列的最大长度是 2 ,所以 answer[0] = 2 。
16+
- 子序列 [4,5,1] 的和小于或等于 10 。可以证明满足题目要求的子序列的最大长度是 3 ,所以 answer[1] = 3 。
17+
- 子序列 [4,5,2,1] 的和小于或等于 21 。可以证明满足题目要求的子序列的最大长度是 4 ,所以 answer[2] = 4 。
18+
</pre>
19+
20+
<p><strong>示例 2:</strong></p>
21+
22+
<pre>
23+
<strong>输入:</strong>nums = [2,3,4,5], queries = [1]
24+
<strong>输出:</strong>[0]
25+
<strong>解释:</strong>空子序列是唯一一个满足元素和小于或等于 1 的子序列,所以 answer[0] = 0 。</pre>
26+
27+
<p>&nbsp;</p>
28+
29+
<p><strong>提示:</strong></p>
30+
31+
<ul>
32+
<li><code>n == nums.length</code></li>
33+
<li><code>m == queries.length</code></li>
34+
<li><code>1 &lt;= n, m &lt;= 1000</code></li>
35+
<li><code>1 &lt;= nums[i], queries[i] &lt;= 10<sup>6</sup></code></li>
36+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的字符串数组&nbsp;<code>garbage</code>&nbsp;,其中&nbsp;<code>garbage[i]</code>&nbsp;表示第 <code>i</code>&nbsp;个房子的垃圾集合。<code>garbage[i]</code>&nbsp;只包含字符&nbsp;<code>'M'</code>&nbsp;,<code>'P'</code> 和&nbsp;<code>'G'</code>&nbsp;,但可能包含多个相同字符,每个字符分别表示一单位的金属、纸和玻璃。垃圾车收拾 <strong></strong>&nbsp;单位的任何一种垃圾都需要花费&nbsp;<code>1</code>&nbsp;分钟。</p>
2+
3+
<p>同时给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>travel</code>&nbsp;,其中&nbsp;<code>travel[i]</code>&nbsp;是垃圾车从房子 <code>i</code>&nbsp;行驶到房子 <code>i + 1</code>&nbsp;需要的分钟数。</p>
4+
5+
<p>城市里总共有三辆垃圾车,分别收拾三种垃圾。每辆垃圾车都从房子 <code>0</code>&nbsp;出发,<strong>按顺序</strong>&nbsp;到达每一栋房子。但它们 <strong>不是必须</strong>&nbsp;到达所有的房子。</p>
6+
7+
<p>任何时刻只有 <strong>一辆</strong>&nbsp;垃圾车处在使用状态。当一辆垃圾车在行驶或者收拾垃圾的时候,另外两辆车 <strong>不能</strong>&nbsp;做任何事情。</p>
8+
9+
<p>请你返回收拾完所有垃圾需要花费的 <strong>最少</strong>&nbsp;总分钟数。</p>
10+
11+
<p>&nbsp;</p>
12+
13+
<p><strong>示例 1:</strong></p>
14+
15+
<pre><b>输入:</b>garbage = ["G","P","GP","GG"], travel = [2,4,3]
16+
<b>输出:</b>21
17+
<strong>解释:</strong>
18+
收拾纸的垃圾车:
19+
1. 从房子 0 行驶到房子 1
20+
2. 收拾房子 1 的纸垃圾
21+
3. 从房子 1 行驶到房子 2
22+
4. 收拾房子 2 的纸垃圾
23+
收拾纸的垃圾车总共花费 8 分钟收拾完所有的纸垃圾。
24+
收拾玻璃的垃圾车:
25+
1. 收拾房子 0 的玻璃垃圾
26+
2. 从房子 0 行驶到房子 1
27+
3. 从房子 1 行驶到房子 2
28+
4. 收拾房子 2 的玻璃垃圾
29+
5. 从房子 2 行驶到房子 3
30+
6. 收拾房子 3 的玻璃垃圾
31+
收拾玻璃的垃圾车总共花费 13 分钟收拾完所有的玻璃垃圾。
32+
由于没有金属垃圾,收拾金属的垃圾车不需要花费任何时间。
33+
所以总共花费 8 + 13 = 21 分钟收拾完所有垃圾。
34+
</pre>
35+
36+
<p><strong>示例 2:</strong></p>
37+
38+
<pre><b>输入:</b>garbage = ["MMM","PGM","GP"], travel = [3,10]
39+
<b>输出:</b>37
40+
<strong>解释:</strong>
41+
收拾金属的垃圾车花费 7 分钟收拾完所有的金属垃圾。
42+
收拾纸的垃圾车花费 15 分钟收拾完所有的纸垃圾。
43+
收拾玻璃的垃圾车花费 15 分钟收拾完所有的玻璃垃圾。
44+
总共花费 7 + 15 + 15 = 37 分钟收拾完所有的垃圾。
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
49+
<p><strong>提示:</strong></p>
50+
51+
<ul>
52+
<li><code>2 &lt;= garbage.length &lt;= 10<sup>5</sup></code></li>
53+
<li><code>garbage[i]</code> 只包含字母&nbsp;<code>'M'</code>&nbsp;,<code>'P'</code>&nbsp;和&nbsp;<code>'G'</code>&nbsp;。</li>
54+
<li><code>1 &lt;= garbage[i].length &lt;= 10</code></li>
55+
<li><code>travel.length == garbage.length - 1</code></li>
56+
<li><code>1 &lt;= travel[i] &lt;= 100</code></li>
57+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<p>给你一个 <strong></strong>&nbsp;整数&nbsp;<code>k</code>&nbsp;,同时给你:</p>
2+
3+
<ul>
4+
<li>一个大小为 <code>n</code>&nbsp;的二维整数数组&nbsp;<code>rowConditions</code>&nbsp;,其中&nbsp;<code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>&nbsp;和</li>
5+
<li>一个大小为 <code>m</code>&nbsp;的二维整数数组&nbsp;<code>colConditions</code>&nbsp;,其中&nbsp;<code>colConditions[i] = [left<sub>i</sub>, right<sub>i</sub>]</code>&nbsp;。</li>
6+
</ul>
7+
8+
<p>两个数组里的整数都是&nbsp;<code>1</code>&nbsp;到&nbsp;<code>k</code>&nbsp;之间的数字。</p>
9+
10+
<p>你需要构造一个&nbsp;<code>k x k</code>&nbsp;的矩阵,<code>1</code>&nbsp;到&nbsp;<code>k</code>&nbsp;每个数字需要&nbsp;<strong>恰好出现一次</strong>&nbsp;。剩余的数字都是<b>&nbsp;</b><code>0</code>&nbsp;。</p>
11+
12+
<p>矩阵还需要满足以下条件:</p>
13+
14+
<ul>
15+
<li>对于所有 <code>0</code>&nbsp;到&nbsp;<code>n - 1</code>&nbsp;之间的下标&nbsp;<code>i</code>&nbsp;,数字&nbsp;<code>above<sub>i</sub></code>&nbsp;所在的 <strong></strong>&nbsp;必须在数字&nbsp;<code>below<sub>i</sub></code>&nbsp;所在行的上面。</li>
16+
<li>对于所有 <code>0</code>&nbsp;到 <code>m - 1</code>&nbsp;之间的下标&nbsp;<code>i</code>&nbsp;,数字&nbsp;<code>left<sub>i</sub></code>&nbsp;所在的 <b></b>&nbsp;必须在数字&nbsp;<code>right<sub>i</sub></code>&nbsp;所在列的左边。</li>
17+
</ul>
18+
19+
<p>返回满足上述要求的 <strong>任意</strong>&nbsp;矩阵。如果不存在答案,返回一个空的矩阵。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong>示例 1:</strong></p>
24+
25+
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/07/06/gridosdrawio.png" style="width: 211px; height: 211px;"></p>
26+
27+
<pre><b>输入:</b>k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]]
28+
<b>输出:</b>[[3,0,0],[0,0,1],[0,2,0]]
29+
<b>解释:</b>上图为一个符合所有条件的矩阵。
30+
行要求如下:
31+
- 数字 1 在第 <strong>1</strong> 行,数字 2 在第 <strong>2</strong>&nbsp;行,1 在 2 的上面。
32+
- 数字 3 在第 <strong>0</strong>&nbsp;行,数字 2 在第 <strong>2</strong>&nbsp;行,3 在 2 的上面。
33+
列要求如下:
34+
- 数字 2 在第 <strong>1</strong>&nbsp;列,数字 1 在第 <strong>2</strong>&nbsp;列,2 在 1 的左边。
35+
- 数字 3 在第 <strong>0</strong>&nbsp;列,数字 2 在第 <strong>1</strong>&nbsp;列,3 在 2 的左边。
36+
注意,可能有多种正确的答案。
37+
</pre>
38+
39+
<p><strong>示例 2:</strong></p>
40+
41+
<pre><b>输入:</b>k = 3, rowConditions = [[1,2],[2,3],[3,1],[2,3]], colConditions = [[2,1]]
42+
<b>输出:</b>[]
43+
<b>解释:</b>由前两个条件可以得到 3 在 1 的下面,但第三个条件是 3 在 1 的上面。
44+
没有符合条件的矩阵存在,所以我们返回空矩阵。
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
49+
<p><strong>提示:</strong></p>
50+
51+
<ul>
52+
<li><code>2 &lt;= k &lt;= 400</code></li>
53+
<li><code>1 &lt;= rowConditions.length, colConditions.length &lt;= 10<sup>4</sup></code></li>
54+
<li><code>rowConditions[i].length == colConditions[i].length == 2</code></li>
55+
<li><code>1 &lt;= above<sub>i</sub>, below<sub>i</sub>, left<sub>i</sub>, right<sub>i</sub> &lt;= k</code></li>
56+
<li><code>above<sub>i</sub> != below<sub>i</sub></code></li>
57+
<li><code>left<sub>i</sub> != right<sub>i</sub></code></li>
58+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p>
2+
3+
<p>In one operation, you can:</p>
4+
5+
<ul>
6+
<li>Choose a star in <code>s</code>.</li>
7+
<li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong>, as well as remove the star itself.</li>
8+
</ul>
9+
10+
<p>Return <em>the string after <strong>all</strong> stars have been removed</em>.</p>
11+
12+
<p><strong>Note:</strong></p>
13+
14+
<ul>
15+
<li>The input will be generated such that the operation is always possible.</li>
16+
<li>It can be shown that the resulting string will always be unique.</li>
17+
</ul>
18+
19+
<p>&nbsp;</p>
20+
<p><strong>Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> s = &quot;leet**cod*e&quot;
24+
<strong>Output:</strong> &quot;lecoe&quot;
25+
<strong>Explanation:</strong> Performing the removals from left to right:
26+
- The closest character to the 1<sup>st</sup> star is &#39;t&#39; in &quot;lee<strong><u>t</u></strong>**cod*e&quot;. s becomes &quot;lee*cod*e&quot;.
27+
- The closest character to the 2<sup>nd</sup> star is &#39;e&#39; in &quot;le<strong><u>e</u></strong>*cod*e&quot;. s becomes &quot;lecod*e&quot;.
28+
- The closest character to the 3<sup>rd</sup> star is &#39;d&#39; in &quot;leco<strong><u>d</u></strong>*e&quot;. s becomes &quot;lecoe&quot;.
29+
There are no more stars, so we return &quot;lecoe&quot;.</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> s = &quot;erase*****&quot;
35+
<strong>Output:</strong> &quot;&quot;
36+
<strong>Explanation:</strong> The entire string is removed, so we return an empty string.
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Constraints:</strong></p>
41+
42+
<ul>
43+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
44+
<li><code>s</code> consists of lowercase English letters and stars <code>*</code>.</li>
45+
<li>The operation above can be performed on <code>s</code>.</li>
46+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<p>You are given an integer array <code>nums</code> of length <code>n</code>, and an integer array <code>queries</code> of length <code>m</code>.</p>
2+
3+
<p>Return <em>an array </em><code>answer</code><em> of length </em><code>m</code><em> where </em><code>answer[i]</code><em> is the <strong>maximum</strong> size of a <strong>subsequence</strong> that you can take from </em><code>nums</code><em> such that the <strong>sum</strong> of its elements is less than or equal to </em><code>queries[i]</code>.</p>
4+
5+
<p>A <strong>subsequence</strong> is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong>Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> nums = [4,5,2,1], queries = [3,10,21]
12+
<strong>Output:</strong> [2,3,4]
13+
<strong>Explanation:</strong> We answer the queries as follows:
14+
- The subsequence [2,1] has a sum less than or equal to 3. It can be proven that 2 is the maximum size of such a subsequence, so answer[0] = 2.
15+
- The subsequence [4,5,1] has a sum less than or equal to 10. It can be proven that 3 is the maximum size of such a subsequence, so answer[1] = 3.
16+
- The subsequence [4,5,2,1] has a sum less than or equal to 21. It can be proven that 4 is the maximum size of such a subsequence, so answer[2] = 4.
17+
</pre>
18+
19+
<p><strong>Example 2:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [2,3,4,5], queries = [1]
23+
<strong>Output:</strong> [0]
24+
<strong>Explanation:</strong> The empty subsequence is the only subsequence that has a sum less than or equal to 1, so answer[0] = 0.</pre>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Constraints:</strong></p>
28+
29+
<ul>
30+
<li><code>n == nums.length</code></li>
31+
<li><code>m == queries.length</code></li>
32+
<li><code>1 &lt;= n, m &lt;= 1000</code></li>
33+
<li><code>1 &lt;= nums[i], queries[i] &lt;= 10<sup>6</sup></code></li>
34+
</ul>

0 commit comments

Comments
 (0)