-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlt32.cpp
46 lines (43 loc) · 1.17 KB
/
lt32.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
class Solution {
public:
vector<int> findSubstring(string s, vector<string>& words) {
int n = s.size();
int n2 = words.size();
int main = words[0].size();
vector<int> result;
bool match = false;
map<char, int> index;
for (int i = 0; i < n2; i++) {
char temp;
temp = words[i][0];
index[temp] = i;
}
int l = 0;
int r = 0;
while (r < n) {
if (index.find(s[r]) == index.end()) {
l++;
r++;
} else {
int neededindex = r;
int count = index[s[r]];
for (auto j : words[count]) {
if (j == s[r]) {
match = true;
r++;
} else {
match = false;
r = l + 1;
l = r;
break;
}
}
if (match) {
result.push_back(neededindex);
l = r;
}
}
}
return result;
}
};