Isomorphic Strings
Given strings s and t, determine if they are isomorphic.
The strings is isomorphic if the characters in s can is replaced to get t.
All occurrences of a character must is replaced with another character while preserving the order of characters. No, characters may map to the same character and a character may map to itself.
For example,
Given "egg"
, "add"
return True.
Given "foo"
, "bar"
return FALSE.
Given "paper"
, "title"
return True.
Note:
Assume both
sand
THas the same length.
classsolution{Private: intGetPos (string&s,CharChintN) { for(intI=0; i<=n; ++i)if(S[i] = =ch)returni; return 0; } Public: BOOLIsisomorphic (stringSstringt) {intLENS =s.size (); intLent =t.size (); if(Lens! =lent)return false; Vector<int>temp; for(intI=0; i<lens; ++i) Temp.push_back (GetPos (S, s[i], i)); for(intI=0; i<lent; ++i)if(GetPos (t, T[i], i)! =Temp[i])return false; return true; }};
[Leetcode] Isomorphic Strings