Simple and easy understanding Java code


  • 0
    X
    public boolean isIsomorphic(String s, String t) {
        char array1[] = s.toCharArray();
        char array2[] = t.toCharArray();
        HashMap<Character, Character> map = new HashMap<Character, Character>();
        for (int i=0;i<array1.length;i++){
            if (map.containsKey(array1[i])){
                if (map.get(array1[i]) != array2[i])
                    return false;
            }
            else{
                if (map.containsValue(array2[i]))
                    return false;
                else
                    map.put(array1[i], array2[i]);
            }
        }
        return true;
    }

Log in to reply
 

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