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.
Hide Tags
1 //08:182 classSolution {3 Public:4 BOOLIsisomorphic (stringSstringt) {5 intSlen =s.size ();6 intTlen =t.size ();7 if(Slen! =Tlen) {8 return false;9 }Ten Chartbl[ the] = {0}; One BOOLused[ the] = {0}; A for(intI=0; i<slen; i++) { - CharCH =S[i]; - if(Tbl[ch] = =0&&!Used[t[i]]) { theTBL[CH] =T[i]; -Used[t[i]] =true; - Continue; - } + if(Tbl[ch]! =T[i]) { - return false; + } A } at return true; - } -};
Leetcode isomorphic Strings