leetcode_686
Solutions
class Solution {
public:
int repeatedStringMatch(string A, string B) {
int maxcnt = (B.size() / A.size()) + 2;
int cnt = ceil((double)B.size() / A.size());
string s;
for (int i = 1; i <= cnt; i++)
s += A;
for (; cnt <= maxcnt; cnt++) {
if(s.find(B) != string::npos)
return cnt;
s += A;
}
return -1;
}
};Last updated