Match Substring After Replacement LeetCode solution in C++

1
class Solution {
2
public:
3
bool matchReplacement(string s, string sub, vector<vector<char>> &mappings) {
4
int m(size(s)), n(size(sub));
5
unordered_map<char, unordered_set<char>> mp;
6

7
auto doit = [&](int ind) {
8
for (int i = ind, j = 0; i < ind + n; i++, j++) {
9
if (s[i] == sub[j] or mp[sub[j]].count(s[i])) continue;
10
return false;
11
}
12
return true;
13
};
14

15
for (auto &mapping : mappings) mp[mapping[0]].insert(mapping[1]);
16
;
17
for (int i = 0; i <= m - n; i++)
18
if (doit(i)) return true;
19
return false;
20
}
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0