Class Solution

java.lang.Object
g0601_0700.s0686_repeated_string_match.Solution

public class Solution extends java.lang.Object
686 - Repeated String Match.

Medium

Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b to be a substring of a after repeating it, return -1.

Notice: string "abc" repeated 0 times is "", repeated 1 time is "abc" and repeated 2 times is "abcabc".

Example 1:

Input: a = “abcd”, b = “cdabcdab”

Output: 3

Explanation: We return 3 because by repeating a three times “abcdabcdabcd”, b is a substring of it.

Example 2:

Input: a = “a”, b = “aa”

Output: 2

Constraints:

  • 1 <= a.length, b.length <= 104
  • a and b consist of lowercase English letters.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    repeatedStringMatch(java.lang.String a, java.lang.String b)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • repeatedStringMatch

      public int repeatedStringMatch(java.lang.String a, java.lang.String b)