同构字符串

同构字符串

/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
var isIsomorphic = function(s, t) {
    let a = {}
    let b = {}
    let len = s.length
    for (let i = 0; i < len; i++) {
        const x = s[i]
        const y = t[i]
        if (a[x] && a[x] !== y  || b[y] && b[y] !== x) {
            return false
        }
        a[x] = y
        b[y] = x
    }
    return true
};

你可能感兴趣的:(同构字符串)