建立一个单映射字符映射表:任何一个字符只能映射到唯一的一个字符,而且也只能被唯一 一个字符映射
class Solution {
public:
bool isIsomorphic(string s, string t) {
unordered_map<char,char> table; //form a map table
bool flag[256]={0};
for(int i=0;i<s.length();i++)
{
if(table.find(s[i])!=table.end())
{
if(table[s[i]]!=t[i])
return false;
}
else
{
if(!flag[t[i]])
{
table[s[i]]=t[i];
flag[t[i]]=1; //not found ,add new char into the table
}
else
{
return false;
}
}
}
return true;
}
};