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.
public static Boolean isisomorphic (string s, String t) { if (s==null && t==null) return true; else if (s.length ()!=t.length ()) return false; Map<character,character> hm=new hashmap<character,character> (); for (int i=0;i<s.length (); i++) { if (Hm.containskey (S.charat (i))) { if (Hm.get (S.charat (i))!=t.charat (i)) return false; } else if (Hm.containsvalue (T.charat (i))) return false; Forget this condition at the beginning, pay attention to the else hm.put (S.charat (i), T.charat (i)); } return true; }
String (205.Isomorphic Strings)