1
class Solution {
2
public:
3
int repeatedStringMatch(string a, string b) {
4
int m = a.size();
5
int n = b.size();
6
vector<int> d;
7
int mod = n % m;
8
int h = n / m;
9

10
if (mod == 0) {
11
d.push_back(h);
12
d.push_back(h + 1);
13
} else {
14
d.push_back(h + 1);
15
d.push_back(h + 2);
16
}
17
string s = "";
18
string t = "";
19

20
for (int i = 0; i < d[0]; i++) {
21
s += a;
22
}
23
for (int i = 0; i < d[1]; i++) {
24
t += a;
25
}
26

27
int i = 0;
28
int y1 = s.size() - n;
29
int y2 = t.size() - n;
30

31
while (i <= y1) {
32
string x = s.substr(i, n); // cout<<x;
33
if (x == b) {
34
return d[0];
35
break;
36
}
37
i++;
38
}
39
i = 0;
40
while (i <= y2) {
41
string x = t.substr(i, n); // cout<<"ok1"<<x;
42
if (x == b) {
43
return d[1];
44
break;
45
}
46
i++;
47
}
48
return -1;
49
}
50
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0