Number of Matching Subsequences LeetCode solution in C++

1
class Solution {
2
public:
3
int numMatchingSubseq(string s, vector<string> &words) {
4
int ct = 0;
5
unordered_map<string, int> m;
6

7
for (int i = 0; i < words.size(); i++) {
8
m[words[i]]++;
9
}
10

11
for (auto it = m.begin(); it != m.end(); it++) {
12
string k = it->first;
13

14
int z = 0;
15

16
for (int i = 0; i < s.length(); i++) {
17
if (s[i] == k[z])
18
z++;
19
else if (z == k.length())
20
break;
21
}
22
if (z == k.length()) ct = ct + it->second;
23
}
24
return ct;
25
}
26
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0