Open Guyidingsanyu opened 3 years ago
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isIsomorphic = function(s, t) {
if(s.length !== t.length) {
return false
}
let s2t = {}
let t2s = {}
for(let i = 0; i < s.length; i++) {
const x = s[i]
const y = t[i]
// 若已经存在映射,但是对应哈希表中的值却不一致,则return false
if((s2t[x] && s2t[x] !== y) || t2s[y] && t2s[y] !== x) {
return false
}
s2t[x] = y
t2s[y] = x
}
return true
};
同构字符串