mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 23:11:41 +08:00
update
This commit is contained in:
@@ -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>
|
Reference in New Issue
Block a user