mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-04-18 08:39:41 +08:00
update
This commit is contained in:
parent
fc8e794743
commit
76e35939b6
README.md
leetcode-cn
origin-data.json
originData
count-substrings-that-can-be-rearranged-to-contain-a-string-i.jsoncount-substrings-that-can-be-rearranged-to-contain-a-string-ii.jsonminimum-number-of-seconds-to-make-mountain-height-zero.jsonreport-spam-message.json
problem (Chinese)
举报垃圾信息 [report-spam-message].html移山所需的最少秒数 [minimum-number-of-seconds-to-make-mountain-height-zero].html统计重新排列后包含另一个字符串的子字符串数目 I [count-substrings-that-can-be-rearranged-to-contain-a-string-i].html统计重新排列后包含另一个字符串的子字符串数目 II [count-substrings-that-can-be-rearranged-to-contain-a-string-ii].html
problem (English)
举报垃圾信息(English) [report-spam-message].html移山所需的最少秒数(English) [minimum-number-of-seconds-to-make-mountain-height-zero].html统计重新排列后包含另一个字符串的子字符串数目 I(English) [count-substrings-that-can-be-rearranged-to-contain-a-string-i].html统计重新排列后包含另一个字符串的子字符串数目 II(English) [count-substrings-that-can-be-rearranged-to-contain-a-string-ii].html
leetcode
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2024.09.19**
|
||||
> 最后更新日期: **2024.09.23**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
164
leetcode-cn/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-i.json
Normal file
164
leetcode-cn/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-i.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-ii.json
Normal file
164
leetcode-cn/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-ii.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
163
leetcode-cn/originData/report-spam-message.json
Normal file
163
leetcode-cn/originData/report-spam-message.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,41 @@
|
||||
<p>给你一个字符串数组 <code>message</code> 和一个字符串数组 <code>bannedWords</code>。</p>
|
||||
|
||||
<p>如果数组中 <strong>至少</strong> 存在两个单词与 <code>bannedWords</code> 中的任一单词 <strong>完全相同</strong>,则该数组被视为 <strong>垃圾信息</strong>。</p>
|
||||
|
||||
<p>如果数组 <code>message</code> 是垃圾信息,则返回 <code>true</code>;否则返回 <code>false</code>。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">message = ["hello","world","leetcode"], bannedWords = ["world","hello"]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>数组 <code>message</code> 中的 <code>"hello"</code> 和 <code>"world"</code> 都出现在数组 <code>bannedWords</code> 中。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">message = ["hello","programming","fun"], bannedWords = ["world","programming","leetcode"]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>数组 <code>message</code> 中只有一个单词(<code>"programming"</code>)出现在数组 <code>bannedWords</code> 中。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= message.length, bannedWords.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= message[i].length, bannedWords[i].length <= 15</code></li>
|
||||
<li><code>message[i]</code> 和 <code>bannedWords[i]</code> 都只由小写英文字母组成。</li>
|
||||
</ul>
|
80
leetcode-cn/problem (Chinese)/移山所需的最少秒数 [minimum-number-of-seconds-to-make-mountain-height-zero].html
Normal file
80
leetcode-cn/problem (Chinese)/移山所需的最少秒数 [minimum-number-of-seconds-to-make-mountain-height-zero].html
Normal file
@ -0,0 +1,80 @@
|
||||
<p>给你一个整数 <code>mountainHeight</code> 表示山的高度。</p>
|
||||
|
||||
<p>同时给你一个整数数组 <code>workerTimes</code>,表示工人们的工作时间(单位:<strong>秒</strong>)。</p>
|
||||
|
||||
<p>工人们需要 <strong>同时 </strong>进行工作以 <strong>降低 </strong>山的高度。对于工人 <code>i</code> :</p>
|
||||
|
||||
<ul>
|
||||
<li>山的高度降低 <code>x</code>,需要花费 <code>workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x</code> 秒。例如:
|
||||
|
||||
<ul>
|
||||
<li>山的高度降低 1,需要 <code>workerTimes[i]</code> 秒。</li>
|
||||
<li>山的高度降低 2,需要 <code>workerTimes[i] + workerTimes[i] * 2</code> 秒,依此类推。</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>返回一个整数,表示工人们使山的高度降低到 0 所需的 <strong>最少</strong> 秒数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">mountainHeight = 4, workerTimes = [2,1,1]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>将山的高度降低到 0 的一种方式是:</p>
|
||||
|
||||
<ul>
|
||||
<li>工人 0 将高度降低 1,花费 <code>workerTimes[0] = 2</code> 秒。</li>
|
||||
<li>工人 1 将高度降低 2,花费 <code>workerTimes[1] + workerTimes[1] * 2 = 3</code> 秒。</li>
|
||||
<li>工人 2 将高度降低 1,花费 <code>workerTimes[2] = 1</code> 秒。</li>
|
||||
</ul>
|
||||
|
||||
<p>因为工人同时工作,所需的最少时间为 <code>max(2, 3, 1) = 3</code> 秒。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">mountainHeight = 10, workerTimes = [3,2,2,4]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">12</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>工人 0 将高度降低 2,花费 <code>workerTimes[0] + workerTimes[0] * 2 = 9</code> 秒。</li>
|
||||
<li>工人 1 将高度降低 3,花费 <code>workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12</code> 秒。</li>
|
||||
<li>工人 2 将高度降低 3,花费 <code>workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12</code> 秒。</li>
|
||||
<li>工人 3 将高度降低 2,花费 <code>workerTimes[3] + workerTimes[3] * 2 = 12</code> 秒。</li>
|
||||
</ul>
|
||||
|
||||
<p>所需的最少时间为 <code>max(9, 12, 12, 12) = 12</code> 秒。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">mountainHeight = 5, workerTimes = [1]</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">15</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>这个示例中只有一个工人,所以答案是 <code>workerTimes[0] + workerTimes[0] * 2 + workerTimes[0] * 3 + workerTimes[0] * 4 + workerTimes[0] * 5 = 15</code> 秒。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= mountainHeight <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= workerTimes.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= workerTimes[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
49
leetcode-cn/problem (Chinese)/统计重新排列后包含另一个字符串的子字符串数目 I [count-substrings-that-can-be-rearranged-to-contain-a-string-i].html
Normal file
49
leetcode-cn/problem (Chinese)/统计重新排列后包含另一个字符串的子字符串数目 I [count-substrings-that-can-be-rearranged-to-contain-a-string-i].html
Normal file
@ -0,0 +1,49 @@
|
||||
<p>给你两个字符串 <code>word1</code> 和 <code>word2</code> 。</p>
|
||||
|
||||
<p>如果一个字符串 <code>x</code> 重新排列后,<code>word2</code> 是重排字符串的 <span data-keyword="string-prefix">前缀</span> ,那么我们称字符串 <code>x</code> 是 <strong>合法的</strong> 。</p>
|
||||
|
||||
<p>请你返回 <code>word1</code> 中 <strong>合法</strong> <span data-keyword="substring-nonempty">子字符串</span> 的数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>word1 = "bcca", word2 = "abc"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>1</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>唯一合法的子字符串是 <code>"bcca"</code> ,可以重新排列得到 <code>"abcc"</code> ,<code>"abc"</code> 是它的前缀。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "abc"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>10</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>除了长度为 1 和 2 的所有子字符串都是合法的。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "aaabc"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>0</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word1.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= word2.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>word1</code> 和 <code>word2</code> 都只包含小写英文字母。</li>
|
||||
</ul>
|
51
leetcode-cn/problem (Chinese)/统计重新排列后包含另一个字符串的子字符串数目 II [count-substrings-that-can-be-rearranged-to-contain-a-string-ii].html
Normal file
51
leetcode-cn/problem (Chinese)/统计重新排列后包含另一个字符串的子字符串数目 II [count-substrings-that-can-be-rearranged-to-contain-a-string-ii].html
Normal file
@ -0,0 +1,51 @@
|
||||
<p>给你两个字符串 <code>word1</code> 和 <code>word2</code> 。</p>
|
||||
|
||||
<p>如果一个字符串 <code>x</code> 重新排列后,<code>word2</code> 是重排字符串的 <span data-keyword="string-prefix">前缀</span> ,那么我们称字符串 <code>x</code> 是 <strong>合法的</strong> 。</p>
|
||||
|
||||
<p>请你返回 <code>word1</code> 中 <strong>合法</strong> <span data-keyword="substring-nonempty">子字符串</span> 的数目。</p>
|
||||
|
||||
<p><strong>注意</strong> ,这个问题中的内存限制比其他题目要 <strong>小</strong> ,所以你 <strong>必须</strong> 实现一个线性复杂度的解法。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>word1 = "bcca", word2 = "abc"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>1</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>唯一合法的子字符串是 <code>"bcca"</code> ,可以重新排列得到 <code>"abcc"</code> ,<code>"abc"</code> 是它的前缀。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "abc"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>10</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>除了长度为 1 和 2 的所有子字符串都是合法的。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>word1 = "abcabc", word2 = "aaabc"</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>0</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word1.length <= 10<sup>6</sup></code></li>
|
||||
<li><code>1 <= word2.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>word1</code> 和 <code>word2</code> 都只包含小写英文字母。</li>
|
||||
</ul>
|
@ -0,0 +1,39 @@
|
||||
<p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Return <code>true</code> if the array <code>message</code> is spam, and <code>false</code> otherwise.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">message = ["hello","world","leetcode"], bannedWords = ["world","hello"]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The words <code>"hello"</code> and <code>"world"</code> from the <code>message</code> array both appear in the <code>bannedWords</code> array.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">message = ["hello","programming","fun"], bannedWords = ["world","programming","leetcode"]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Only one word from the <code>message</code> array (<code>"programming"</code>) appears in the <code>bannedWords</code> array.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= message.length, bannedWords.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= message[i].length, bannedWords[i].length <= 15</code></li>
|
||||
<li><code>message[i]</code> and <code>bannedWords[i]</code> consist only of lowercase English letters.</li>
|
||||
</ul>
|
78
leetcode-cn/problem (English)/移山所需的最少秒数(English) [minimum-number-of-seconds-to-make-mountain-height-zero].html
Normal file
78
leetcode-cn/problem (English)/移山所需的最少秒数(English) [minimum-number-of-seconds-to-make-mountain-height-zero].html
Normal file
@ -0,0 +1,78 @@
|
||||
<p>You are given an integer <code>mountainHeight</code> denoting the height of a mountain.</p>
|
||||
|
||||
<p>You are also given an integer array <code>workerTimes</code> representing the work time of workers in <strong>seconds</strong>.</p>
|
||||
|
||||
<p>The workers work <strong>simultaneously</strong> to <strong>reduce</strong> the height of the mountain. For worker <code>i</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li>To decrease the mountain's height by <code>x</code>, it takes <code>workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x</code> seconds. For example:
|
||||
|
||||
<ul>
|
||||
<li>To reduce the height of the mountain by 1, it takes <code>workerTimes[i]</code> seconds.</li>
|
||||
<li>To reduce the height of the mountain by 2, it takes <code>workerTimes[i] + workerTimes[i] * 2</code> seconds, and so on.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<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>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 4, workerTimes = [2,1,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>One way the height of the mountain can be reduced to 0 is:</p>
|
||||
|
||||
<ul>
|
||||
<li>Worker 0 reduces the height by 1, taking <code>workerTimes[0] = 2</code> seconds.</li>
|
||||
<li>Worker 1 reduces the height by 2, taking <code>workerTimes[1] + workerTimes[1] * 2 = 3</code> seconds.</li>
|
||||
<li>Worker 2 reduces the height by 1, taking <code>workerTimes[2] = 1</code> second.</li>
|
||||
</ul>
|
||||
|
||||
<p>Since they work simultaneously, the minimum time needed is <code>max(2, 3, 1) = 3</code> seconds.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 10, workerTimes = [3,2,2,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">12</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Worker 0 reduces the height by 2, taking <code>workerTimes[0] + workerTimes[0] * 2 = 9</code> seconds.</li>
|
||||
<li>Worker 1 reduces the height by 3, taking <code>workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12</code> seconds.</li>
|
||||
<li>Worker 2 reduces the height by 3, taking <code>workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12</code> seconds.</li>
|
||||
<li>Worker 3 reduces the height by 2, taking <code>workerTimes[3] + workerTimes[3] * 2 = 12</code> seconds.</li>
|
||||
</ul>
|
||||
|
||||
<p>The number of seconds needed is <code>max(9, 12, 12, 12) = 12</code> seconds.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 5, workerTimes = [1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">15</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= mountainHeight <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= workerTimes.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= workerTimes[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
47
leetcode-cn/problem (English)/统计重新排列后包含另一个字符串的子字符串数目 I(English) [count-substrings-that-can-be-rearranged-to-contain-a-string-i].html
Normal file
47
leetcode-cn/problem (English)/统计重新排列后包含另一个字符串的子字符串数目 I(English) [count-substrings-that-can-be-rearranged-to-contain-a-string-i].html
Normal file
@ -0,0 +1,47 @@
|
||||
<p>You are given two strings <code>word1</code> and <code>word2</code>.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Return the total number of <strong>valid</strong> <span data-keyword="substring-nonempty">substrings</span> of <code>word1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "bcca", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only valid substring is <code>"bcca"</code> which can be rearranged to <code>"abcc"</code> having <code>"abc"</code> as a prefix.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">10</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the substrings except substrings of size 1 and size 2 are valid.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "aaabc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word1.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= word2.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>word1</code> and <code>word2</code> consist only of lowercase English letters.</li>
|
||||
</ul>
|
49
leetcode-cn/problem (English)/统计重新排列后包含另一个字符串的子字符串数目 II(English) [count-substrings-that-can-be-rearranged-to-contain-a-string-ii].html
Normal file
49
leetcode-cn/problem (English)/统计重新排列后包含另一个字符串的子字符串数目 II(English) [count-substrings-that-can-be-rearranged-to-contain-a-string-ii].html
Normal file
@ -0,0 +1,49 @@
|
||||
<p>You are given two strings <code>word1</code> and <code>word2</code>.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Return the total number of <strong>valid</strong> <span data-keyword="substring-nonempty">substrings</span> of <code>word1</code>.</p>
|
||||
|
||||
<p><strong>Note</strong> that the memory limits in this problem are <strong>smaller</strong> than usual, so you <strong>must</strong> implement a solution with a <em>linear</em> runtime complexity.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "bcca", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only valid substring is <code>"bcca"</code> which can be rearranged to <code>"abcc"</code> having <code>"abc"</code> as a prefix.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">10</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the substrings except substrings of size 1 and size 2 are valid.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "aaabc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word1.length <= 10<sup>6</sup></code></li>
|
||||
<li><code>1 <= word2.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>word1</code> and <code>word2</code> consist only of lowercase English letters.</li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
161
leetcode/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-i.json
Normal file
161
leetcode/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-i.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-ii.json
Normal file
161
leetcode/originData/count-substrings-that-can-be-rearranged-to-contain-a-string-ii.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
160
leetcode/originData/report-spam-message.json
Normal file
160
leetcode/originData/report-spam-message.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,47 @@
|
||||
<p>You are given two strings <code>word1</code> and <code>word2</code>.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Return the total number of <strong>valid</strong> <span data-keyword="substring-nonempty">substrings</span> of <code>word1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "bcca", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only valid substring is <code>"bcca"</code> which can be rearranged to <code>"abcc"</code> having <code>"abc"</code> as a prefix.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">10</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the substrings except substrings of size 1 and size 2 are valid.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "aaabc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word1.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= word2.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>word1</code> and <code>word2</code> consist only of lowercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>You are given two strings <code>word1</code> and <code>word2</code>.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Return the total number of <strong>valid</strong> <span data-keyword="substring-nonempty">substrings</span> of <code>word1</code>.</p>
|
||||
|
||||
<p><strong>Note</strong> that the memory limits in this problem are <strong>smaller</strong> than usual, so you <strong>must</strong> implement a solution with a <em>linear</em> runtime complexity.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "bcca", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only valid substring is <code>"bcca"</code> which can be rearranged to <code>"abcc"</code> having <code>"abc"</code> as a prefix.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">10</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All the substrings except substrings of size 1 and size 2 are valid.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word1 = "abcabc", word2 = "aaabc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word1.length <= 10<sup>6</sup></code></li>
|
||||
<li><code>1 <= word2.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>word1</code> and <code>word2</code> consist only of lowercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,78 @@
|
||||
<p>You are given an integer <code>mountainHeight</code> denoting the height of a mountain.</p>
|
||||
|
||||
<p>You are also given an integer array <code>workerTimes</code> representing the work time of workers in <strong>seconds</strong>.</p>
|
||||
|
||||
<p>The workers work <strong>simultaneously</strong> to <strong>reduce</strong> the height of the mountain. For worker <code>i</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li>To decrease the mountain's height by <code>x</code>, it takes <code>workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x</code> seconds. For example:
|
||||
|
||||
<ul>
|
||||
<li>To reduce the height of the mountain by 1, it takes <code>workerTimes[i]</code> seconds.</li>
|
||||
<li>To reduce the height of the mountain by 2, it takes <code>workerTimes[i] + workerTimes[i] * 2</code> seconds, and so on.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<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>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 4, workerTimes = [2,1,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>One way the height of the mountain can be reduced to 0 is:</p>
|
||||
|
||||
<ul>
|
||||
<li>Worker 0 reduces the height by 1, taking <code>workerTimes[0] = 2</code> seconds.</li>
|
||||
<li>Worker 1 reduces the height by 2, taking <code>workerTimes[1] + workerTimes[1] * 2 = 3</code> seconds.</li>
|
||||
<li>Worker 2 reduces the height by 1, taking <code>workerTimes[2] = 1</code> second.</li>
|
||||
</ul>
|
||||
|
||||
<p>Since they work simultaneously, the minimum time needed is <code>max(2, 3, 1) = 3</code> seconds.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 10, workerTimes = [3,2,2,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">12</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Worker 0 reduces the height by 2, taking <code>workerTimes[0] + workerTimes[0] * 2 = 9</code> seconds.</li>
|
||||
<li>Worker 1 reduces the height by 3, taking <code>workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12</code> seconds.</li>
|
||||
<li>Worker 2 reduces the height by 3, taking <code>workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12</code> seconds.</li>
|
||||
<li>Worker 3 reduces the height by 2, taking <code>workerTimes[3] + workerTimes[3] * 2 = 12</code> seconds.</li>
|
||||
</ul>
|
||||
|
||||
<p>The number of seconds needed is <code>max(9, 12, 12, 12) = 12</code> seconds.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">mountainHeight = 5, workerTimes = [1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">15</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= mountainHeight <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= workerTimes.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= workerTimes[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
39
leetcode/problem/report-spam-message.html
Normal file
39
leetcode/problem/report-spam-message.html
Normal file
@ -0,0 +1,39 @@
|
||||
<p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Return <code>true</code> if the array <code>message</code> is spam, and <code>false</code> otherwise.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">message = ["hello","world","leetcode"], bannedWords = ["world","hello"]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The words <code>"hello"</code> and <code>"world"</code> from the <code>message</code> array both appear in the <code>bannedWords</code> array.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">message = ["hello","programming","fun"], bannedWords = ["world","programming","leetcode"]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Only one word from the <code>message</code> array (<code>"programming"</code>) appears in the <code>bannedWords</code> array.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= message.length, bannedWords.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= message[i].length, bannedWords[i].length <= 15</code></li>
|
||||
<li><code>message[i]</code> and <code>bannedWords[i]</code> consist only of lowercase English letters.</li>
|
||||
</ul>
|
Loading…
x
Reference in New Issue
Block a user