-
Notifications
You must be signed in to change notification settings - Fork 0
/
686.hpp
39 lines (34 loc) · 866 Bytes
/
686.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef LEETCODE_686_HPP
#define LEETCODE_686_HPP
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
class Solution {
public:
int repeatedStringMatch(string A, string B) {
int mtimes = -1;
for (int i = 0; i < A.length(); ++i) {
int j = 0;
while (j < B.size() ) {
if (A[(i + j) % A.length()] != B[j]){
if (i + j >= A.length())
return -1;
break;
}
j++;
}
if (j == B.size())
return static_cast<int>((i + j + A.length() - 1) / A.length());
}
return -1;
}
};
#endif //LEETCODE_686_HPP