-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path0792.cpp
More file actions
26 lines (23 loc) · 681 Bytes
/
Copy path0792.cpp
File metadata and controls
26 lines (23 loc) · 681 Bytes
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
class Solution {
public:
int numMatchingSubseq(const string &s, const vector<string> &words) const {
static int pos[50001][26];
const int n = size(s);
int res = 0;
memset(pos[n], 0x00, sizeof(pos[n]));
for (int i = n - 1; i >= 0; i--) {
memcpy(pos[i], pos[i + 1], sizeof(pos[i]));
pos[i][s[i] - 'a'] = i + 1;
}
for (const auto &word : words) {
int crnt = 0;
for (const char c : word) {
if (!pos[crnt][c - 'a']) goto next;
crnt = pos[crnt][c - 'a'];
}
res++;
next:;
}
return res;
}
};