题目:
题目:
思路:直接调用 205. 同构字符串 的代码判断 word 是否与 t 是同构字符串,然后进行添加即可。
代码如下:
class Solution {
public:
vector findAndReplacePattern(vector& words, string s) {
vector res;
for(auto& t:words)
if(check(s,t))res.push_back(t);
return res;
}
// 双hash:s->t t->s
bool check(string& s, string& t) {
unordered_map r1,r2;
int n=s.size();
for(int i=0;i
char a=s[i],b=t[i];
if(r1.count(a)&&r1[a]!=b||r2.count(b)&&r2[b]!=a)return false;
r1[a]=b,r2[b]=a;
}
return true;
}
};


![[字符串映射]leetcode890:查找和替换模式(medium) [字符串映射]leetcode890:查找和替换模式(medium)](http://www.mshxw.com/aiimages/31/968187.png)
