版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/83445517
https://leetcode.com/problems/repeated-string-match/description/
//A比B的长度要短,这时A要不断增加。 2. A 比 B 刚好长,
//3、A 比 B 刚好长的长度 + 1个A的长度, 这时能够保证在A的原始的串中能够索引完一遍B的长度,如果此时没有找到那么就要返回-1
class Solution {
public:
int repeatedStringMatch(string A, string B) {
int res = 1;
string tmp = A;
while(tmp.size() < B.size()){
tmp += A;
res +=1;
}
if(tmp.find(B)!=-1)return res;
tmp += A, res+=1;
if(tmp.find(B)!=-1) return res;
return -1;
}
};