My Java Solution with Map


  • 0
    class Solution {
        public boolean isIsomorphic(String sstr, String tstr) {
            char[] s = sstr.toCharArray(), t = tstr.toCharArray();
            int[] m1 = new int[256], m2 = new int[256];
            for (int i = 0; i < s.length; ++i) {
                if (m1[s[i]] != m2[t[i]]) return false;
                m1[s[i]] = i + 1;
                m2[t[i]] = i + 1;
            }
            return true;
        }
    };
    

Log in to reply
 

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