@@ -0,0 +1,2250 @@
+import org.junit.After;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%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 of characters. No%0A * two characters may map to the same character but a character may map to 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 * %3Cp%3E%0A * Tags: Hash Table%0A * Similar Problems: (E) Word Pattern%0A */%0Apublic class IsomorphicStrings %7B%0A%0A    private IsomorphicStrings is;%0A%0A    /**%0A     * Store the last seen positions of current (i-th) characters in both strings.%0A     */%0A    public boolean isIsomorphic(String s, String t) %7B%0A        if (s == null %7C%7C t == null) return false;%0A        int%5B%5D m = new int%5B512%5D;%0A        int len = s.length();%0A        for (int i = 0; i %3C len; i++) %7B%0A            if (m%5Bs.charAt(i)%5D != m%5Bt.charAt(i) + 256%5D) return false;%0A            m%5Bs.charAt(i)%5D = m%5Bt.charAt(i) + 256%5D = i + 1;%0A        %7D%0A        return true;%0A    %7D%0A%0A    @Before%0A    public void setUp() %7B%0A        is = new IsomorphicStrings();%0A    %7D%0A%0A    @Test%0A    public void testEdgeCases() %7B%0A        Assert.assertFalse(is.isIsomorphic(null, null));%0A        Assert.assertFalse(is.isIsomorphic(null, %22%22));%0A        Assert.assertFalse(is.isIsomorphic(%22%22, null));%0A        Assert.assertTrue(is.isIsomorphic(%22%22, %22%22));%0A    %7D%0A%0A    @Test%0A    public void testExamples() %7B%0A        // %22egg%22, %22add%22, return true%0A        Assert.assertTrue(is.isIsomorphic(%22egg%22, %22add%22));%0A        // %22foo%22, %22bar%22, return false%0A        Assert.assertFalse(is.isIsomorphic(%22foo%22, %22bar%22));%0A        // %22paper%22, %22title%22, return true%0A        Assert.assertTrue(is.isIsomorphic(%22paper%22, %22title%22));%0A        // %22papper%22, %22tittle%22, return true%0A        Assert.assertTrue(is.isIsomorphic(%22papper%22, %22tittle%22));%0A        // %22abba%22, %22abab%22%0A        Assert.assertFalse(is.isIsomorphic(%22abba%22, %22abab%22));%0A    %7D%0A%0A    @After%0A    public void tearDown() %7B%0A        is = null;%0A    %7D%0A%0A%7D%0A

add Isomorphic Strings