Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 793 Bytes

205. Isomorphic Strings.md

File metadata and controls

31 lines (25 loc) · 793 Bytes

205. Isomorphic Strings

Isomorphic Strings - LeetCode

import java.util.Hashtable;
class Solution {
    public static boolean isIsomorphic(String s, String t) {
        if (s.length() != t.length()) return false;

        Hashtable<Character , Character> hashtable = new Hashtable<>();
        for (int i = 0; i < s.length(); i++) 
        {
            char c1 = s.charAt(i);
            char c2 = t.charAt(i);
            
            if (hashtable.containsKey(c1))
            {
                if (hashtable.get(c1) != c2) return false;
            }else {
                if (hashtable.containsValue(c2)) return false;
                hashtable.put(c1 , c2);
            }
        }

        return true;
    }
}

a