就是匹配字符串
class Solution {
public int repeatedStringMatch(String A, String B) {
if(B.length()==0) return 0;
int len = B.length()/A.length();
int count = 1;
String C = A;
while(C.indexOf(B)<0){
C += A;
count++;
if(count-len>2){
return -1;
}
}
return count;
}
}
精髓就是indexOf()。就不用自己手写KMP了。