686 Repeated String Match
import math
import copy
class Solution:
def repeatedStringMatch(self, A, B):
"""
:type A: str
:type B: str
:rtype: int
"""
A_cp = copy.deepcopy(A)
n_fit = math.ceil(len(B) / len(A))
A *= n_fit
if B in A: return n_fit
A += A_cp
if B in A: return n_fit + 1
return -1
obj = Solution()
print(obj.repeatedStringMatch('abababaaba', 'aabaaba')) # 2
print(obj.repeatedStringMatch('abcd', 'cdab')) # 2
print(obj.repeatedStringMatch('abcd', 'cdabcdab')) # 3Last updated