check isIsomorphic
var isIsomorphic = function(s, t) {
let firstOccurance = {};
let secondOccurance = {};
if(s.length !== t.length) return false;
for(let i=0; i<s.length; i++){
let char1=s[i];
let char2=t[i];
if(!firstOccurance[char1] && !secondOccurance[char2]){
firstOccurance[char1]= char2;
secondOccurance[char2]= char1;
}
if(firstOccurance[char1] !== char2 && secondOccurance[char2] !== char1){
return false
}
}
return true;
};
Top comments (0)