DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

isIsomorphic

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;

};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)