Java 2ms


  • 0
    R
        public boolean isIsomorphic(String s, String t) {
            if (s.length() != t.length()) return false;
            char[] table = new char[256];
            char[] table2 = new char[256];
            char[] sArr = s.toCharArray();
            char[] tArr = t.toCharArray();
            for (int i = 0; i < sArr.length; i++) {
                char cS = sArr[i];
                char cT = tArr[i];
                if (table[cS] == 0) {
                    table[cS] = cT;
                    if (table2[cT] != 0) return false;
                    table2[cT] = cS;
                }
                else if (table[cS] != cT) return false;
            }
            return true;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.