@@ -0,0 +1,1336 @@
+package com.pengyifan.leetcode;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Given two strings s and t, determine if they are isomorphic.%0A * %3Cp%3E%0A * Two strings are isomorphic if the characters in s can be replaced to get t.%0A * %3Cp%3E%0A * All occurrences of a character must be replaced with another character while preserving the order%0A * of characters. No two characters may map to the same character but a character may map to%0A * itself.%0A * %3Cp%3E%0A * For example,%0A * Given %22egg%22, %22add%22, return true.%0A * %3Cp%3E%0A * Given %22foo%22, %22bar%22, return false.%0A * %3Cp%3E%0A * Given %22paper%22, %22title%22, return true.%0A * %3Cp%3E%0A * Note:%0A * You may assume both s and t have the same length.%0A */%0Apublic class IsomorphicStrings %7B%0A  public boolean isIsomorphic(String s, String t) %7B%0A    if (s == null %7C%7C t == null %7C%7C s.length() != t.length()) %7B%0A      return false;%0A    %7D%0A    Map%3CCharacter, Character%3E map1 = new HashMap%3C%3E();%0A    Map%3CCharacter, Character%3E map2 = new HashMap%3C%3E();%0A    for (int i = 0; i %3C s.length(); i++) %7B%0A      if (map1.containsKey(s.charAt(i))) %7B%0A        if (t.charAt(i) != map1.get(s.charAt(i))) %7B%0A          return false;%0A        %7D%0A      %7D else if (map2.containsKey(t.charAt(i))) %7B%0A        return false;%0A      %7D else %7B%0A        map1.put(s.charAt(i), t.charAt(i));%0A        map2.put(t.charAt(i), s.charAt(i));%0A      %7D%0A    %7D%0A    return true;%0A  %7D%0A%7D%0A

Isomorphic Strings