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 be replaced with another character while preserving the order of characters. No. Characters may map to the same character but a character may map to itself.
for example,
Given "egg" , "add" , return true.
given "foo" , "bar" , return false.
Given "paper" , "title" return True.
The topic analysis, two strings between the one by one mapping relationship, using hash to deal with, because it consists of two strings, so you must build two hash map table, to ensure two strings between the one by one correspondence between the characters
public class Solution {
public Boolean isisomorphic (string s, String t) {
Hashmap<character,character> map1=new Hashmap<character, character> ();
Hashmap<character,character> map2=new Hashmap<character, character> ();
for (int i=0;i<s.length (); i++)
{
if (Map1.get (S.charat (i)) ==null)
Map1.put (S.charat (i), T.charat (i));
if (Map2.get (T.charat (i)) ==null)
Map2.put (T.charat (i), S.charat (i));
if (Map1.get (S.charat (i))!=t.charat (i) | | Map2.get (T.charat (i))!=s.charat (i))
return false;
}
return true;
}
}
Leetcode#205isomorphic Strings