leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0792.cpp (681B)


0 class Solution { 1 public: 2 int numMatchingSubseq(const string &s, const vector<string> &words) const { 3 static int pos[50001][26]; 4 const int n = size(s); 5 int res = 0; 6 7 memset(pos[n], 0x00, sizeof(pos[n])); 8 for (int i = n - 1; i >= 0; i--) { 9 memcpy(pos[i], pos[i + 1], sizeof(pos[i])); 10 pos[i][s[i] - 'a'] = i + 1; 11 } 12 13 for (const auto &word : words) { 14 int crnt = 0; 15 for (const char c : word) { 16 if (!pos[crnt][c - 'a']) goto next; 17 crnt = pos[crnt][c - 'a']; 18 } 19 res++; 20 next:; 21 } 22 23 return res; 24 } 25 };