Is Strings Isomorphic - Solution

 πŸ‘€βœŒAlso Download our app CodeBox  from Play Store for offline use πŸ‘€βœŒ


SOLUTION


bool isIsomorphic(string s, string t){
int hash[256] = {0}, is_mapped[256] = {0};
for(int i =0 ; i < s.size() ; i++){
if (hash[s[i]] == 0 && is_mapped[t[i]] == 0)
{
hash[s[i]] = t[i];
is_mapped[t[i]] = 1;
}
}
for (int i = 0; i < t.size(); i++)
{
if (hash[s[i]] != t[i])
{
return false;
}
}
return true;
}

Comments