-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq26_map.cpp
67 lines (63 loc) · 1.31 KB
/
q26_map.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
static const auto __ = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
return nullptr;
}();
class Solution {
public:
static vector<int> findSubstring(string s, vector<string>& words) {
vector<int> r;
if (words.size() == 0) return r;
int n = words[0].size(), len = words.size()*n;
string patt;
int end = s.size()-len;
unordered_map<string,int> count;
for(int i=0;i<words.size();++i) ++count[words[i]];
for (int i = 0; i<n; ++i) {
int posi = i;
while (posi <= end) {
unordered_map<string,int> flags;
int drop(0),start=posi;
for (int j = 0; j<words.size(); ++j) {
int num=count[s.substr(posi,n)];
if (num!=0) {
if (flags[s.substr(posi,n)] == num) {
posi += n;
drop = j + 1;
break;
}
++flags[s.substr(posi,n)];
posi += n;
continue;
}
posi += n;
drop = j + 1;
break;
}
//posi += n;
if (drop) {
posi = start + n;
continue;
}
r.push_back(start);
while (true) {
int flag(0);
for (int t = 0; t<n; t++) {
if (s[start+t] != s[posi + t]) {
flag = 1;
break;
}
}
start += n;
posi += n;
if (flag) {
posi = start + n;
break;
}
r.push_back(start);
}
}
}
return r;
}
};