|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>给定一个字符串 <code>s</code><strong> </strong>和一些 <strong>长度相同</strong> 的单词 <code>words</code><strong> 。</strong>找出 <code>s</code><strong> </strong>中恰好可以由 <code>words</code><strong> </strong>中所有单词串联形成的子串的起始位置。</p> |
| 9 | +<p>给定一个字符串 <code>s</code><strong> </strong>和一个字符串数组 <code>words</code><strong>。</strong> <code>words</code> 中所有字符串 <strong>长度相同</strong>。</p> |
10 | 10 |
|
11 |
| -<p>注意子串要与 <code>words</code><strong> </strong>中的单词完全匹配,<strong>中间不能有其他字符 </strong>,但不需要考虑 <code>words</code><strong> </strong>中单词串联的顺序。</p> |
| 11 | +<p> <code>s</code><strong> </strong>中的 <strong>串联子串</strong> 是指一个包含 <code>words</code> 中所有字符串以任意顺序排列连接起来的子串。</p> |
12 | 12 |
|
13 |
| -<p> </p> |
| 13 | +<ul> |
| 14 | + <li>例如,如果 <code>words = ["ab","cd","ef"]</code>, 那么 <code>"abcdef"</code>, <code>"abefcd"</code>,<code>"cdabef"</code>, <code>"cdefab"</code>,<code>"efabcd"</code>, 和 <code>"efcdab"</code> 都是串联子串。 <code>"acdbef"</code> 不是串联子串,因为他不是任何 <code>words</code> 排列的连接。</li> |
| 15 | +</ul> |
| 16 | + |
| 17 | +<p>返回所有串联字串在 <code>s</code><strong> </strong>中的开始索引。你可以以 <strong>任意顺序</strong> 返回答案。</p> |
| 18 | + |
| 19 | +<p> </p> |
14 | 20 |
|
15 | 21 | <p><strong>示例 1:</strong></p>
|
16 | 22 |
|
17 | 23 | <pre>
|
18 | 24 | <strong>输入:</strong>s = "barfoothefoobarman", words = ["foo","bar"]
|
19 | 25 | <strong>输出:</strong><code>[0,9]</code>
|
20 |
| -<strong>解释:</strong> |
21 |
| -从索引 0 和 9 开始的子串分别是 "barfoo" 和 "foobar" 。 |
22 |
| -输出的顺序不重要, [9,0] 也是有效答案。 |
| 26 | +<strong>解释:</strong>因为 words.length == 2 同时 words[i].length == 3,连接的子字符串的长度必须为 6。 |
| 27 | +子串 "barfoo" 开始位置是 0。它是 words 中以 ["bar","foo"] 顺序排列的连接。 |
| 28 | +子串 "foobar" 开始位置是 9。它是 words 中以 ["foo","bar"] 顺序排列的连接。 |
| 29 | +输出顺序无关紧要。返回 [9,0] 也是可以的。 |
23 | 30 | </pre>
|
24 | 31 |
|
25 | 32 | <p><strong>示例 2:</strong></p>
|
26 | 33 |
|
27 | 34 | <pre>
|
28 | 35 | <strong>输入:</strong>s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
|
29 | 36 | <code><strong>输出:</strong>[]</code>
|
| 37 | +<strong>解释:</strong>因为<strong> </strong>words.length == 4 并且 words[i].length == 4,所以串联子串的长度必须为 16。 |
| 38 | +s 中没有子串长度为 16 并且等于 words 的任何顺序排列的连接。 |
| 39 | +所以我们返回一个空数组。 |
30 | 40 | </pre>
|
31 | 41 |
|
32 | 42 | <p><strong>示例 3:</strong></p>
|
33 | 43 |
|
34 | 44 | <pre>
|
35 | 45 | <strong>输入:</strong>s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
|
36 | 46 | <strong>输出:</strong>[6,9,12]
|
37 |
| -</pre> |
| 47 | +<strong>解释:</strong>因为 words.length == 3 并且 words[i].length == 3,所以串联子串的长度必须为 9。 |
| 48 | +子串 "foobarthe" 开始位置是 6。它是 words 中以 ["foo","bar","the"] 顺序排列的连接。 |
| 49 | +子串 "barthefoo" 开始位置是 9。它是 words 中以 ["bar","the","foo"] 顺序排列的连接。 |
| 50 | +子串 "thefoobar" 开始位置是 12。它是 words 中以 ["the","foo","bar"] 顺序排列的连接。</pre> |
38 | 51 |
|
39 |
| -<p> </p> |
| 52 | +<p> </p> |
40 | 53 |
|
41 | 54 | <p><strong>提示:</strong></p>
|
42 | 55 |
|
43 | 56 | <ul>
|
44 |
| - <li><code>1 <= s.length <= 10<sup>4</sup></code></li> |
45 |
| - <li><code>s</code> 由小写英文字母组成</li> |
46 |
| - <li><code>1 <= words.length <= 5000</code></li> |
47 |
| - <li><code>1 <= words[i].length <= 30</code></li> |
48 |
| - <li><code>words[i]</code> 由小写英文字母组成</li> |
| 57 | + <li><code>1 <= s.length <= 10<sup>4</sup></code></li> |
| 58 | + <li><code>1 <= words.length <= 5000</code></li> |
| 59 | + <li><code>1 <= words[i].length <= 30</code></li> |
| 60 | + <li><code>words[i]</code> 和 <code>s</code> 由小写英文字母组成</li> |
49 | 61 | </ul>
|
50 | 62 |
|
51 | 63 | ## 解法
|
|
0 commit comments