1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/重复叠加字符串匹配 [repeated-string-match].html

41 lines
1.4 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>给定两个字符串&nbsp;<code>a</code><code>b</code>,寻找重复叠加字符串 <code>a</code> 的最小次数,使得字符串 <code>b</code> 成为叠加后的字符串 <code>a</code> 的子串,如果不存在则返回 <code>-1</code></p>
<p><strong>注意:</strong>字符串 <code>&quot;abc&quot;</code>&nbsp;重复叠加 0 次是 <code>&quot;&quot;</code>,重复叠加 1 次是&nbsp;<code>&quot;abc&quot;</code>,重复叠加 2 次是&nbsp;<code>&quot;abcabc&quot;</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>a = &quot;abcd&quot;, b = &quot;cdabcdab&quot;
<strong>输出:</strong>3
<strong>解释:</strong>a 重复叠加三遍后为 &quot;ab<strong>cdabcdab</strong>cd&quot;, 此时 b 是其子串。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>a = &quot;a&quot;, b = &quot;aa&quot;
<strong>输出:</strong>2
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>a = &quot;a&quot;, b = &quot;a&quot;
<strong>输出:</strong>1
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>a = &quot;abc&quot;, b = &quot;wxyz&quot;
<strong>输出:</strong>-1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= a.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= b.length &lt;= 10<sup>4</sup></code></li>
<li><code>a</code><code>b</code> 由小写英文字母组成</li>
</ul>