您的位置:首页 > 其它

leetcode 686 Repeated String Match

2018-03-28 11:28 337 查看
686Repeated 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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: