Skip to content

Commit f50c612

Browse files
committed
Runtime: 890 ms (Top 66.93%) | Memory: 18 MB (Top 68.52%)
1 parent f46a2e4 commit f50c612

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
// Runtime: 890 ms (Top 66.93%) | Memory: 18 MB (Top 68.52%)
12
class Solution {
23
public:
34
bool matchReplacement(string s, string sub, vector<vector<char>>& mappings) {
4-
5+
56
int m(size(s)), n(size(sub));
67
unordered_map<char, unordered_set<char>> mp;
7-
8+
89
auto doit = [&](int ind) {
9-
10+
1011
for (int i=ind, j=0; i<ind+n; i++, j++) {
11-
if (s[i] == sub[j] or mp[sub[j]].count(s[i])) continue;
12+
if (s[i] == sub[j] or mp[sub[j]].count(s[i])) continue;
1213
return false;
1314
}
1415
return true;
1516
};
16-
17-
for (auto& mapping : mappings) mp[mapping[0]].insert(mapping[1]);;
18-
for (int i=0; i<=m-n; i++) if (doit(i)) return true;
17+
18+
for (auto& mapping : mappings) mp[mapping[0]].insert(mapping[1]);;
19+
for (int i=0; i<=m-n; i++) if (doit(i)) return true;
1920
return false;
2021
}
21-
};
22+
};

0 commit comments

Comments
 (0)