版权声明:本文为博主原创文章,请尊重原创,转载请注明原文地址和作者信息! https://blog.csdn.net/zzc15806/article/details/82526245
class Solution:
# 穷举法
def repeatedStringMatch(self, A, B):
"""
:type A: str
:type B: str
:rtype: int
"""
cnt = 1
la = len(A)
a = A
while cnt*la <= 10000:
if B in A:
return cnt
else:
A += a
cnt += 1
return -1
class Solution:
def repeatedStringMatch(self, A, B):
"""
:type A: str
:type B: str
:rtype: int
"""
cnt = int(math.ceil(len(B) / len(A)))
Ar = A*cnt
if B in Ar:
return cnt
Ar += A
cnt += 1
if B in Ar:
return cnt
return -1