1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 11:08:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/串联所有单词的子串 [substring-with-concatenation-of-all-words].html
2022-03-29 12:43:11 +08:00

42 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>给定一个字符串 <code>s</code><strong> </strong>和一些 <strong>长度相同</strong> 的单词 <code>words</code><strong></strong>找出 <code>s</code><strong> </strong>中恰好可以由 <code>words</code><strong> </strong>中所有单词串联形成的子串的起始位置。</p>
<p>注意子串要与 <code>words</code><strong> </strong>中的单词完全匹配,<strong>中间不能有其他字符 </strong>,但不需要考虑 <code>words</code><strong> </strong>中单词串联的顺序。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "barfoothefoobarman", words = ["foo","bar"]
<strong>输出:</strong><code>[0,9]</code>
<strong>解释:</strong>
从索引 0 和 9 开始的子串分别是 "barfoo" 和 "foobar" 。
输出的顺序不重要, [9,0] 也是有效答案。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
<code><strong>输出:</strong>[]</code>
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
<strong>输出:</strong>[6,9,12]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
<li><code>s</code> 由小写英文字母组成</li>
<li><code>1 <= words.length <= 5000</code></li>
<li><code>1 <= words[i].length <= 30</code></li>
<li><code>words[i]</code> 由小写英文字母组成</li>
</ul>