686 | Repeated String Match | 33.90% | string b要重复多少次才包含string a,循环最多重复b/a+1次(li718) |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 12 21:45:08 2018
@author: vicky
"""
class Solution:
def repeatedStringMatch(self, A, B):
"""
:type A: str
:type B: str
:rtype: int
"""
k=0
C=str()
while k <= len(B)/len(A)+1:#注意要加1,可能刚好是len(B)/len(A)
C=A+C
k=k+1
if B in C:
return k
return -1
A="abcd"
B="cdabcdab"
print(Solution().repeatedStringMatch(A,B))