java.lang.Object
g0001_0100.s0030_substring_with_concatenation_of_all_words.Solution

public class Solution extends Object
30 - Substring with Concatenation of All Words.<p>Hard</p> <p>You are given a string <code>s</code> and an array of strings <code>words</code> of <strong>the same length</strong>. Return all starting indices of substring(s) in <code>s</code> that is a concatenation of each word in <code>words</code> <strong>exactly once</strong> , <strong>in any order</strong> , and <strong>without any intervening characters</strong>.</p> <p>You can return the answer in <strong>any order</strong>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;barfoothefoobarman&rdquo;, words = [&ldquo;foo&rdquo;,&ldquo;bar&rdquo;]</p> <p><strong>Output:</strong> [0,9]</p> <p><strong>Explanation:</strong> Substrings starting at index 0 and 9 are &ldquo;barfoo&rdquo; and &ldquo;foobar&rdquo; respectively. The output order does not matter, returning [9,0] is fine too.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;wordgoodgoodgoodbestword&rdquo;, words = [&ldquo;word&rdquo;,&ldquo;good&rdquo;,&ldquo;best&rdquo;,&ldquo;word&rdquo;]</p> <p><strong>Output:</strong> []</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;barfoofoobarthefoobarman&rdquo;, words = [&ldquo;bar&rdquo;,&ldquo;foo&rdquo;,&ldquo;the&rdquo;]</p> <p><strong>Output:</strong> [6,9,12]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>4</sup></code></li> <li><code>s</code> consists of lower-case English letters.</li> <li><code>1 <= words.length <= 5000</code></li> <li><code>1 <= words[i].length <= 30</code></li> <li><code>words[i]</code> consists of lower-case English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details