Skip to content

Commit 76e3593

Browse files
author
zhangbk1
committed
update
1 parent fc8e794 commit 76e3593

File tree

23 files changed

+16869
-14748
lines changed

23 files changed

+16869
-14748
lines changed

Diff for: README.md

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

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

Diff for: leetcode-cn/origin-data.json

+8,229-8,145
Large diffs are not rendered by default.

Diff for: leetcode-cn/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-i.json

+164
Large diffs are not rendered by default.

Diff for: leetcode-cn/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-ii.json

+164
Large diffs are not rendered by default.

Diff for: leetcode-cn/originData/minimum-number-of-seconds-to-make-mountain-height-zero.json

+164
Large diffs are not rendered by default.

Diff for: leetcode-cn/originData/report-spam-message.json

+163
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<p>给你一个字符串数组 <code>message</code> 和一个字符串数组 <code>bannedWords</code></p>
2+
3+
<p>如果数组中 <strong>至少</strong> 存在两个单词与 <code>bannedWords</code> 中的任一单词 <strong>完全相同</strong>,则该数组被视为 <strong>垃圾信息</strong></p>
4+
5+
<p>如果数组 <code>message</code> 是垃圾信息,则返回 <code>true</code>;否则返回 <code>false</code></p>
6+
7+
<p>&nbsp;</p>
8+
9+
<p><strong class="example">示例 1:</strong></p>
10+
11+
<div class="example-block">
12+
<p><strong>输入:</strong> <span class="example-io">message = ["hello","world","leetcode"], bannedWords = ["world","hello"]</span></p>
13+
14+
<p><strong>输出:</strong> <span class="example-io">true</span></p>
15+
16+
<p><strong>解释:</strong></p>
17+
18+
<p>数组 <code>message</code> 中的 <code>"hello"</code><code>"world"</code> 都出现在数组 <code>bannedWords</code> 中。</p>
19+
</div>
20+
21+
<p><strong class="example">示例 2:</strong></p>
22+
23+
<div class="example-block">
24+
<p><strong>输入:</strong> <span class="example-io">message = ["hello","programming","fun"], bannedWords = ["world","programming","leetcode"]</span></p>
25+
26+
<p><strong>输出:</strong> <span class="example-io">false</span></p>
27+
28+
<p><strong>解释:</strong></p>
29+
30+
<p>数组 <code>message</code> 中只有一个单词(<code>"programming"</code>)出现在数组 <code>bannedWords</code> 中。</p>
31+
</div>
32+
33+
<p>&nbsp;</p>
34+
35+
<p><strong>提示:</strong></p>
36+
37+
<ul>
38+
<li><code>1 &lt;= message.length, bannedWords.length &lt;= 10<sup>5</sup></code></li>
39+
<li><code>1 &lt;= message[i].length, bannedWords[i].length &lt;= 15</code></li>
40+
<li><code>message[i]</code><code>bannedWords[i]</code> 都只由小写英文字母组成。</li>
41+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<p>给你一个整数 <code>mountainHeight</code> 表示山的高度。</p>
2+
3+
<p>同时给你一个整数数组 <code>workerTimes</code>,表示工人们的工作时间(单位:<strong></strong>)。</p>
4+
5+
<p>工人们需要 <strong>同时 </strong>进行工作以 <strong>降低 </strong>山的高度。对于工人 <code>i</code> :</p>
6+
7+
<ul>
8+
<li>山的高度降低 <code>x</code>,需要花费 <code>workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x</code> 秒。例如:
9+
10+
<ul>
11+
<li>山的高度降低 1,需要 <code>workerTimes[i]</code> 秒。</li>
12+
<li>山的高度降低 2,需要 <code>workerTimes[i] + workerTimes[i] * 2</code> 秒,依此类推。</li>
13+
</ul>
14+
</li>
15+
</ul>
16+
17+
<p>返回一个整数,表示工人们使山的高度降低到 0 所需的 <strong>最少</strong> 秒数。</p>
18+
19+
<p>&nbsp;</p>
20+
21+
<p><strong class="example">示例 1:</strong></p>
22+
23+
<div class="example-block">
24+
<p><strong>输入:</strong> <span class="example-io">mountainHeight = 4, workerTimes = [2,1,1]</span></p>
25+
26+
<p><strong>输出:</strong> <span class="example-io">3</span></p>
27+
28+
<p><strong>解释:</strong></p>
29+
30+
<p>将山的高度降低到 0 的一种方式是:</p>
31+
32+
<ul>
33+
<li>工人 0 将高度降低 1,花费 <code>workerTimes[0] = 2</code> 秒。</li>
34+
<li>工人 1 将高度降低 2,花费 <code>workerTimes[1] + workerTimes[1] * 2 = 3</code> 秒。</li>
35+
<li>工人 2 将高度降低 1,花费 <code>workerTimes[2] = 1</code> 秒。</li>
36+
</ul>
37+
38+
<p>因为工人同时工作,所需的最少时间为 <code>max(2, 3, 1) = 3</code> 秒。</p>
39+
</div>
40+
41+
<p><strong class="example">示例 2:</strong></p>
42+
43+
<div class="example-block">
44+
<p><strong>输入:</strong> <span class="example-io">mountainHeight = 10, workerTimes = [3,2,2,4]</span></p>
45+
46+
<p><strong>输出:</strong> <span class="example-io">12</span></p>
47+
48+
<p><strong>解释:</strong></p>
49+
50+
<ul>
51+
<li>工人 0 将高度降低 2,花费 <code>workerTimes[0] + workerTimes[0] * 2 = 9</code> 秒。</li>
52+
<li>工人 1 将高度降低 3,花费 <code>workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12</code> 秒。</li>
53+
<li>工人 2 将高度降低 3,花费 <code>workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12</code> 秒。</li>
54+
<li>工人 3 将高度降低 2,花费 <code>workerTimes[3] + workerTimes[3] * 2 = 12</code> 秒。</li>
55+
</ul>
56+
57+
<p>所需的最少时间为 <code>max(9, 12, 12, 12) = 12</code> 秒。</p>
58+
</div>
59+
60+
<p><strong class="example">示例 3:</strong></p>
61+
62+
<div class="example-block">
63+
<p><strong>输入:</strong> <span class="example-io">mountainHeight = 5, workerTimes = [1]</span></p>
64+
65+
<p><strong>输出:</strong> <span class="example-io">15</span></p>
66+
67+
<p><strong>解释:</strong></p>
68+
69+
<p>这个示例中只有一个工人,所以答案是 <code>workerTimes[0] + workerTimes[0] * 2 + workerTimes[0] * 3 + workerTimes[0] * 4 + workerTimes[0] * 5 = 15</code> 秒。</p>
70+
</div>
71+
72+
<p>&nbsp;</p>
73+
74+
<p><strong>提示:</strong></p>
75+
76+
<ul>
77+
<li><code>1 &lt;= mountainHeight &lt;= 10<sup>5</sup></code></li>
78+
<li><code>1 &lt;= workerTimes.length &lt;= 10<sup>4</sup></code></li>
79+
<li><code>1 &lt;= workerTimes[i] &lt;= 10<sup>6</sup></code></li>
80+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<p>给你两个字符串&nbsp;<code>word1</code> 和&nbsp;<code>word2</code>&nbsp;。</p>
2+
3+
<p>如果一个字符串 <code>x</code>&nbsp;重新排列后,<code>word2</code>&nbsp;是重排字符串的&nbsp;<span data-keyword="string-prefix">前缀</span>&nbsp;,那么我们称字符串&nbsp;<code>x</code>&nbsp;是&nbsp;<strong>合法的</strong>&nbsp;。</p>
4+
5+
<p>请你返回 <code>word1</code>&nbsp;中 <strong>合法</strong>&nbsp;<span data-keyword="substring-nonempty">子字符串</span>&nbsp;的数目。</p>
6+
7+
<p>&nbsp;</p>
8+
9+
<p><strong class="example">示例 1:</strong></p>
10+
11+
<div class="example-block">
12+
<p><span class="example-io"><b>输入:</b>word1 = "bcca", word2 = "abc"</span></p>
13+
14+
<p><span class="example-io"><b>输出:</b>1</span></p>
15+
16+
<p><strong>解释:</strong></p>
17+
18+
<p>唯一合法的子字符串是&nbsp;<code>"bcca"</code>&nbsp;,可以重新排列得到&nbsp;<code>"abcc"</code>&nbsp;,<code>"abc"</code>&nbsp;是它的前缀。</p>
19+
</div>
20+
21+
<p><strong class="example">示例 2:</strong></p>
22+
23+
<div class="example-block">
24+
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "abc"</span></p>
25+
26+
<p><span class="example-io"><b>输出:</b>10</span></p>
27+
28+
<p><strong>解释:</strong></p>
29+
30+
<p>除了长度为 1 和 2 的所有子字符串都是合法的。</p>
31+
</div>
32+
33+
<p><strong class="example">示例 3:</strong></p>
34+
35+
<div class="example-block">
36+
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "aaabc"</span></p>
37+
38+
<p><span class="example-io"><b>输出:</b>0</span></p>
39+
</div>
40+
41+
<p>&nbsp;</p>
42+
43+
<p><strong>解释:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= word1.length &lt;= 10<sup>5</sup></code></li>
47+
<li><code>1 &lt;= word2.length &lt;= 10<sup>4</sup></code></li>
48+
<li><code>word1</code> 和&nbsp;<code>word2</code>&nbsp;都只包含小写英文字母。</li>
49+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<p>给你两个字符串&nbsp;<code>word1</code> 和&nbsp;<code>word2</code>&nbsp;。</p>
2+
3+
<p>如果一个字符串 <code>x</code>&nbsp;重新排列后,<code>word2</code>&nbsp;是重排字符串的&nbsp;<span data-keyword="string-prefix">前缀</span>&nbsp;,那么我们称字符串&nbsp;<code>x</code>&nbsp;是&nbsp;<strong>合法的</strong>&nbsp;。</p>
4+
5+
<p>请你返回 <code>word1</code>&nbsp;中 <strong>合法</strong>&nbsp;<span data-keyword="substring-nonempty">子字符串</span>&nbsp;的数目。</p>
6+
7+
<p><strong>注意</strong>&nbsp;,这个问题中的内存限制比其他题目要&nbsp;<strong></strong>&nbsp;,所以你&nbsp;<strong>必须</strong>&nbsp;实现一个线性复杂度的解法。</p>
8+
9+
<p>&nbsp;</p>
10+
11+
<p><strong class="example">示例 1:</strong></p>
12+
13+
<div class="example-block">
14+
<p><span class="example-io"><b>输入:</b>word1 = "bcca", word2 = "abc"</span></p>
15+
16+
<p><span class="example-io"><b>输出:</b>1</span></p>
17+
18+
<p><strong>解释:</strong></p>
19+
20+
<p>唯一合法的子字符串是&nbsp;<code>"bcca"</code>&nbsp;,可以重新排列得到&nbsp;<code>"abcc"</code>&nbsp;,<code>"abc"</code>&nbsp;是它的前缀。</p>
21+
</div>
22+
23+
<p><strong class="example">示例 2:</strong></p>
24+
25+
<div class="example-block">
26+
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "abc"</span></p>
27+
28+
<p><span class="example-io"><b>输出:</b>10</span></p>
29+
30+
<p><strong>解释:</strong></p>
31+
32+
<p>除了长度为 1 和 2 的所有子字符串都是合法的。</p>
33+
</div>
34+
35+
<p><strong class="example">示例 3:</strong></p>
36+
37+
<div class="example-block">
38+
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "aaabc"</span></p>
39+
40+
<p><span class="example-io"><b>输出:</b>0</span></p>
41+
</div>
42+
43+
<p>&nbsp;</p>
44+
45+
<p><strong>解释:</strong></p>
46+
47+
<ul>
48+
<li><code>1 &lt;= word1.length &lt;= 10<sup>6</sup></code></li>
49+
<li><code>1 &lt;= word2.length &lt;= 10<sup>4</sup></code></li>
50+
<li><code>word1</code> 和&nbsp;<code>word2</code>&nbsp;都只包含小写英文字母。</li>
51+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
2+
3+
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
4+
5+
<p>Return <code>true</code> if the array <code>message</code> is spam, and <code>false</code> otherwise.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<div class="example-block">
11+
<p><strong>Input:</strong> <span class="example-io">message = [&quot;hello&quot;,&quot;world&quot;,&quot;leetcode&quot;], bannedWords = [&quot;world&quot;,&quot;hello&quot;]</span></p>
12+
13+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
14+
15+
<p><strong>Explanation:</strong></p>
16+
17+
<p>The words <code>&quot;hello&quot;</code> and <code>&quot;world&quot;</code> from the <code>message</code> array both appear in the <code>bannedWords</code> array.</p>
18+
</div>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<div class="example-block">
23+
<p><strong>Input:</strong> <span class="example-io">message = [&quot;hello&quot;,&quot;programming&quot;,&quot;fun&quot;], bannedWords = [&quot;world&quot;,&quot;programming&quot;,&quot;leetcode&quot;]</span></p>
24+
25+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
26+
27+
<p><strong>Explanation:</strong></p>
28+
29+
<p>Only one word from the <code>message</code> array (<code>&quot;programming&quot;</code>) appears in the <code>bannedWords</code> array.</p>
30+
</div>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= message.length, bannedWords.length &lt;= 10<sup>5</sup></code></li>
37+
<li><code>1 &lt;= message[i].length, bannedWords[i].length &lt;= 15</code></li>
38+
<li><code>message[i]</code> and <code>bannedWords[i]</code> consist only of lowercase English letters.</li>
39+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<p>You are given an integer <code>mountainHeight</code> denoting the height of a mountain.</p>
2+
3+
<p>You are also given an integer array <code>workerTimes</code> representing the work time of workers in <strong>seconds</strong>.</p>
4+
5+
<p>The workers work <strong>simultaneously</strong> to <strong>reduce</strong> the height of the mountain. For worker <code>i</code>:</p>
6+
7+
<ul>
8+
<li>To decrease the mountain&#39;s height by <code>x</code>, it takes <code>workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x</code> seconds. For example:
9+
10+
<ul>
11+
<li>To reduce the height of the mountain by 1, it takes <code>workerTimes[i]</code> seconds.</li>
12+
<li>To reduce the height of the mountain by 2, it takes <code>workerTimes[i] + workerTimes[i] * 2</code> seconds, and so on.</li>
13+
</ul>
14+
</li>
15+
</ul>
16+
17+
<p>Return an integer representing the <strong>minimum</strong> number of seconds required for the workers to make the height of the mountain 0.</p>
18+
19+
<p>&nbsp;</p>
20+
<p><strong class="example">Example 1:</strong></p>
21+
22+
<div class="example-block">
23+
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 4, workerTimes = [2,1,1]</span></p>
24+
25+
<p><strong>Output:</strong> <span class="example-io">3</span></p>
26+
27+
<p><strong>Explanation:</strong></p>
28+
29+
<p>One way the height of the mountain can be reduced to 0 is:</p>
30+
31+
<ul>
32+
<li>Worker 0 reduces the height by 1, taking <code>workerTimes[0] = 2</code> seconds.</li>
33+
<li>Worker 1 reduces the height by 2, taking <code>workerTimes[1] + workerTimes[1] * 2 = 3</code> seconds.</li>
34+
<li>Worker 2 reduces the height by 1, taking <code>workerTimes[2] = 1</code> second.</li>
35+
</ul>
36+
37+
<p>Since they work simultaneously, the minimum time needed is <code>max(2, 3, 1) = 3</code> seconds.</p>
38+
</div>
39+
40+
<p><strong class="example">Example 2:</strong></p>
41+
42+
<div class="example-block">
43+
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 10, workerTimes = [3,2,2,4]</span></p>
44+
45+
<p><strong>Output:</strong> <span class="example-io">12</span></p>
46+
47+
<p><strong>Explanation:</strong></p>
48+
49+
<ul>
50+
<li>Worker 0 reduces the height by 2, taking <code>workerTimes[0] + workerTimes[0] * 2 = 9</code> seconds.</li>
51+
<li>Worker 1 reduces the height by 3, taking <code>workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12</code> seconds.</li>
52+
<li>Worker 2 reduces the height by 3, taking <code>workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12</code> seconds.</li>
53+
<li>Worker 3 reduces the height by 2, taking <code>workerTimes[3] + workerTimes[3] * 2 = 12</code> seconds.</li>
54+
</ul>
55+
56+
<p>The number of seconds needed is <code>max(9, 12, 12, 12) = 12</code> seconds.</p>
57+
</div>
58+
59+
<p><strong class="example">Example 3:</strong></p>
60+
61+
<div class="example-block">
62+
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 5, workerTimes = [1]</span></p>
63+
64+
<p><strong>Output:</strong> <span class="example-io">15</span></p>
65+
66+
<p><strong>Explanation:</strong></p>
67+
68+
<p>There is only one worker in this example, so the answer is <code>workerTimes[0] + workerTimes[0] * 2 + workerTimes[0] * 3 + workerTimes[0] * 4 + workerTimes[0] * 5 = 15</code>.</p>
69+
</div>
70+
71+
<p>&nbsp;</p>
72+
<p><strong>Constraints:</strong></p>
73+
74+
<ul>
75+
<li><code>1 &lt;= mountainHeight &lt;= 10<sup>5</sup></code></li>
76+
<li><code>1 &lt;= workerTimes.length &lt;= 10<sup>4</sup></code></li>
77+
<li><code>1 &lt;= workerTimes[i] &lt;= 10<sup>6</sup></code></li>
78+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<p>You are given two strings <code>word1</code> and <code>word2</code>.</p>
2+
3+
<p>A string <code>x</code> is called <strong>valid</strong> if <code>x</code> can be rearranged to have <code>word2</code> as a <span data-keyword="string-prefix">prefix</span>.</p>
4+
5+
<p>Return the total number of <strong>valid</strong> <span data-keyword="substring-nonempty">substrings</span> of <code>word1</code>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<div class="example-block">
11+
<p><strong>Input:</strong> <span class="example-io">word1 = &quot;bcca&quot;, word2 = &quot;abc&quot;</span></p>
12+
13+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
14+
15+
<p><strong>Explanation:</strong></p>
16+
17+
<p>The only valid substring is <code>&quot;bcca&quot;</code> which can be rearranged to <code>&quot;abcc&quot;</code> having <code>&quot;abc&quot;</code> as a prefix.</p>
18+
</div>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<div class="example-block">
23+
<p><strong>Input:</strong> <span class="example-io">word1 = &quot;abcabc&quot;, word2 = &quot;abc&quot;</span></p>
24+
25+
<p><strong>Output:</strong> <span class="example-io">10</span></p>
26+
27+
<p><strong>Explanation:</strong></p>
28+
29+
<p>All the substrings except substrings of size 1 and size 2 are valid.</p>
30+
</div>
31+
32+
<p><strong class="example">Example 3:</strong></p>
33+
34+
<div class="example-block">
35+
<p><strong>Input:</strong> <span class="example-io">word1 = &quot;abcabc&quot;, word2 = &quot;aaabc&quot;</span></p>
36+
37+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
38+
</div>
39+
40+
<p>&nbsp;</p>
41+
<p><strong>Constraints:</strong></p>
42+
43+
<ul>
44+
<li><code>1 &lt;= word1.length &lt;= 10<sup>5</sup></code></li>
45+
<li><code>1 &lt;= word2.length &lt;= 10<sup>4</sup></code></li>
46+
<li><code>word1</code> and <code>word2</code> consist only of lowercase English letters.</li>
47+
</ul>

0 commit comments

Comments
 (0)