My easy to understand Java Solution using HashMaps


  • 2
    J
    public class Solution {
    public boolean isIsomorphic(String s, String t) {
        if(s==null&& t==null)return true;
        if(s.length()!=t.length())return false;
        int i=0;
        HashMap<Character,Character> map=new HashMap<Character,Character>();
        while(i<s.length())
        {
            if(map.containsKey(s.charAt(i)))
            {
                char temp= map.get(s.charAt(i));
                if(temp!=t.charAt(i))
                return false;
            }
            else if(map.containsValue(t.charAt(i)))
            return false;
            else
            {
                map.put(s.charAt(i),t.charAt(i));
            }
            i++;
        }
        return true;
        
    }
    

    }


Log in to reply
 

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