Class Solution

java.lang.Object
g0601_0700.s0686_repeated_string_match.Solution

public class Solution extends Object
686 - Repeated String Match.<p>Medium</p> <p>Given two strings <code>a</code> and <code>b</code>, return <em>the minimum number of times you should repeat string</em> <code>a</code> <em>so that string</em> <code>b</code> <em>is a substring of it</em>. If it is impossible for <code>b</code> to be a substring of <code>a</code> after repeating it, return <code>-1</code>.</p> <p><strong>Notice:</strong> string <code>&quot;abc&quot;</code> repeated 0 times is <code>&quot;&quot;</code>, repeated 1 time is <code>&quot;abc&quot;</code> and repeated 2 times is <code>&quot;abcabc&quot;</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> a = &ldquo;abcd&rdquo;, b = &ldquo;cdabcdab&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> We return 3 because by repeating a three times &ldquo;ab<strong>cdabcdab</strong>cd&rdquo;, b is a substring of it.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> a = &ldquo;a&rdquo;, b = &ldquo;aa&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= a.length, b.length <= 10<sup>4</sup></code></li> <li><code>a</code> and <code>b</code> consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • repeatedStringMatch

      public int repeatedStringMatch(String a, String b)