-
Notifications
You must be signed in to change notification settings - Fork 6
/
0792.cpp
41 lines (29 loc) · 891 Bytes
/
0792.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
class Solution {
bool isSubSeq(string s1, string s2, int m, int n) {
int cnt = 0;
for(int i = 0; i < m && cnt < n; i++) {
if (s1[i] == s2[cnt])
cnt++;
}
if (cnt == n)
return true;
else
return false;
}
public:
int numMatchingSubseq(string s, vector<string>& words) {
int cnt = 0;
unordered_map<string, bool> m1;
for(auto& word : words) {
if (m1.find(word) != m1.end()) {
if (m1[word] == true)
cnt++;
continue;
}
m1[word] = isSubSeq(s, word, s.size(), word.size());
if (m1[word])
cnt += 1;
}
return cnt;
}
};