leetcode

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

0890.cpp (831B)


0 class Solution {
1 public:
2 vector<string> findAndReplacePattern(const vector<string> &words, const string &pattern) {
3 vector<string> res;
4 static int um[27] = {0};
5 static bool used[27] = {0};
6 for (const auto &word : words) {
7 for (int i = 0; i < pattern.size(); i++) {
8 const uint8_t w = word[i] & 0x1F;
9 const uint8_t p = pattern[i] & 0x1F;
10 if (um[w]) {
11 if (um[w] != p) goto next;
12 continue;
13 }
14 if (used[p]) goto next;
15 used[p] = true;
16 um[w] = p;
17 }
18 res.push_back(word);
19 next:;
20 memset(um, 0x00, sizeof(um));
21 memset(used, 0x00, sizeof(used));
22 }
24 return res;
25 }
26 };