1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-13 03:11:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
zhangbk1
2024-01-19 16:10:00 +08:00
parent 2817184d94
commit 3a14465651
24 changed files with 16467 additions and 14101 deletions

View File

@@ -0,0 +1,48 @@
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的字符串&nbsp;<code>s</code>&nbsp;、字符串&nbsp;<code>a</code>&nbsp;、字符串&nbsp;<code>b</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;</p>
<p>如果下标 <code>i</code>&nbsp;满足以下条件,则认为它是一个 <strong>美丽下标</strong>&nbsp;</p>
<ul>
<li><code>0 &lt;= i &lt;= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)] == a</code></li>
<li>存在下标&nbsp;<code>j</code>&nbsp;使得:
<ul>
<li><code>0 &lt;= j &lt;= s.length - b.length</code></li>
<li><code>s[j..(j + b.length - 1)] == b</code></li>
<li><code>|j - i| &lt;= k</code></li>
</ul>
</li>
</ul>
<p>以数组形式按<strong>&nbsp;从小到大排序&nbsp;</strong>返回美丽下标。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
<strong>输出:</strong>[16,33]
<strong>解释:</strong>存在 2 个美丽下标:[16,33]。
- 下标 16 是美丽下标,因为 s[16..17] == "my" ,且存在下标 4 ,满足 s[4..11] == "squirrel" 且 |16 - 4| &lt;= 15 。
- 下标 33 是美丽下标,因为 s[33..34] == "my" ,且存在下标 18 ,满足 s[18..25] == "squirrel" 且 |33 - 18| &lt;= 15 。
因此返回 [16,33] 作为结果。</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>s = "abcd", a = "a", b = "a", k = 4
<b>输出:</b>[0]
<strong>解释:</strong>存在 1 个美丽下标:[0]。
- 下标 0 是美丽下标,因为 s[0..0] == "a" ,且存在下标 0 ,满足 s[0..0] == "a" 且 |0 - 0| &lt;= 4 。
因此返回 [0] 作为结果。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= s.length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>1 &lt;= a.length, b.length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>s</code><code>a</code>、和&nbsp;<code>b</code>&nbsp;只包含小写英文字母。</li>
</ul>