686 - Repeated String Match
Written on February 28, 2018
Tweet
Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.
class Solution(object):
def repeatedStringMatch(self, A, B):
"""
:type A: str
:type B: str
:rtype: int
"""
C = ""
for i in range(len(B)/len(A) + 3):
if B in C:
return i
C += A
return -1