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 s and T have the same length.
Title: See if two words are isomorphic. This is an obvious problem with the hash table, but note that no two letters correspond to one letter, but the same letter can be
classSolution { Public: BOOLIsisomorphic (stringSstringt) {map<Char,Char>CHCHMAP,CHCHMAP2; for(Unsigned i =0; i < s.size (); + +i) {if(Chchmap.find (s[i]) = =chchmap.end ()) Chchmap[s[i]=T[i]; Else if(T[i]! =Chchmap[s[i]])return false; if(Chchmap2.find (t[i]) = =chchmap2.end ()) Chchmap2[t[i]=S[i]; Else if(S[i]! =Chchmap2[t[i]])return false; } return true; }};
Leetcode isomorphic Strings