-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path890-kir3i.cpp
More file actions
26 lines (25 loc) · 790 Bytes
/
890-kir3i.cpp
File metadata and controls
26 lines (25 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
public:
vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
int sz = pattern.size();
vector<string> ans;
for(const string &w: words) {
bool ok = true;
unordered_map<char, char> trans;
unordered_set<char> used;
for(int i=0; i<sz && ok; i++) {
if(trans.find(pattern[i]) == trans.end()) {
ok &= (used.find(w[i]) == used.end());
trans[pattern[i]] = w[i];
used.insert(w[i]);
}
else {
ok &= (trans[pattern[i]] == w[i]);
}
}
if(ok)
ans.push_back(w);
}
return ans;
}
};