simple javascript solution


  • 0
    S
     * @param {string} s
     * @param {string} t
     * @return {boolean}
     */
    var isIsomorphic = function(s, t) {
        var mapS = {};
        var mapT = {};
        for(var i=0;i<s.length; i++) {
            if (!mapS[s[i]]) {
                mapS[s[i]] = t[i];
            }
            else if (mapS[s[i]] !== t[i]){
                return false;
            }
            
            if (!mapT[t[i]]) {
                mapT[t[i]] = s[i];
            }
            else if (mapT[t[i]] !== s[i]){
                return false;
            }
        }
        return true;  
    };
    

Log in to reply
 

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