Use two maps to save the relationships from s[i] to t[i] and from t[i] to s[i]. Make sure there is no duplicate.
class Solution {
public:
bool isIsomorphic(string s, string t) {
unordered_map<char,char> mpfrom,mpto;
for(int i=0;i<s.size();i++)
{
if(mpfrom.find(s[i])==mpfrom.end()&&mpto.find(t[i])==mpto.end())
{
mpfrom.insert(make_pair(s[i],t[i]));
mpto.insert(make_pair(t[i],s[i]));
}
else if(mpfrom.find(s[i])!=mpfrom.end()&&mpfrom[s[i]]!=t[i])
return false;
else if(mpto.find(t[i])!=mpto.end()&&mpto[t[i]]!=s[i])
return false;
}
return true;
}
};