1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计重新排列后包含另一个字符串的子字符串数目 I [count-substrings-that-can-be-rearranged-to-contain-a-string-i].html
2024-09-23 14:31:00 +08:00

50 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你两个字符串&nbsp;<code>word1</code>&nbsp;<code>word2</code>&nbsp;</p>
<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>
<p>请你返回 <code>word1</code>&nbsp;<strong>合法</strong>&nbsp;<span data-keyword="substring-nonempty">子字符串</span>&nbsp;的数目。</p>
<p>&nbsp;</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>唯一合法的子字符串是&nbsp;<code>"bcca"</code>&nbsp;,可以重新排列得到&nbsp;<code>"abcc"</code>&nbsp;<code>"abc"</code>&nbsp;是它的前缀。</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>&nbsp;</p>
<p><strong>解释:</strong></p>
<ul>
<li><code>1 &lt;= word1.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= word2.length &lt;= 10<sup>4</sup></code></li>
<li><code>word1</code>&nbsp;<code>word2</code>&nbsp;都只包含小写英文字母。</li>
</ul>