Skip to content

Commit afc522a

Browse files
authored
Update match-substring-after-replacement.cpp
1 parent e673c06 commit afc522a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

C++/match-substring-after-replacement.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
class Solution {
66
public:
77
bool matchReplacement(string s, string sub, vector<vector<char>>& mappings) {
8-
const auto& transform = [](char c) {
8+
const auto& f = [](char c) {
99
return ::isdigit(c) ? c - '0' : (::islower(c) ? c - 'a' + 10 : c - 'A' + 36);
1010
};
1111
vector<vector<bool>> lookup(62, vector<bool>(62));
1212
for (const auto& m : mappings) {
13-
lookup[transform(m[0])][transform(m[1])] = true;
13+
lookup[f(m[0])][f(m[1])] = true;
1414
}
15+
transform(begin(s), end(s), begin(s), f);
16+
transform(begin(sub), end(sub), begin(sub), f);
1517
const auto& check = [&](int i) {
1618
for (int j = 0; j < size(sub); ++j) {
17-
if (sub[j] != s[i + j] && (!lookup[transform(sub[j])][transform(s[i + j])])) {
19+
if (sub[j] != s[i + j] && (!lookup[sub[j]][s[i + j]])) {
1820
return false;
1921
}
2022
}

0 commit comments

Comments
 (0)