Number of Matching Subsequences LeetCode solution in C++
1class Solution {2public:3int numMatchingSubseq(string s, vector<string> &words) {4int ct = 0;5unordered_map<string, int> m;67for (int i = 0; i < words.size(); i++) {8m[words[i]]++;9}1011for (auto it = m.begin(); it != m.end(); it++) {12string k = it->first;1314int z = 0;1516for (int i = 0; i < s.length(); i++) {17if (s[i] == k[z])18z++;19else if (z == k.length())20break;21}22if (z == k.length()) ct = ct + it->second;23}24return ct;25}26};