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.
Maintain two hash tables.
The function of the second hash table is to ensure that no more than two letters are mapped to the same letter.
Class Solution { Public:BOOL isisomorphic(stringSstringT) {inttable[ the] = {0};inttable2[ the] = {0};stringtemp =""; for(inti =0; I < s.size (); i++) {if(Table[s[i]] = =0) {Table[s[i]] = t[i]; }if(Table2[t[i]] = =0) {Table2[t[i]] = s[i]; }Else if(S[i]! = Table2[t[i]])return false; Temp.push_back (Table[s[i]); }if(temp = = t)return true;Else return false; }};
[Leetcode] Isomorphic Strings