mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
50 lines
1.8 KiB
HTML
50 lines
1.8 KiB
HTML
<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>
|