Javascript solution. 139ms


  • 0
    K
    var isIsomorphic = function(s, t) {
      function getpairs(){
        var a = [];
        for (var i=0; i<s.length; i++){
          a[i] = s[i] + t[i];
        }
        return a;
      }
      if(s.length == t.length){
        
        var pairs = getpairs();
        //console.log(pairs());
        for (var i=0; i<s.length; i++){
          var index = s.indexOf(pairs[i][0]);
          if(t[index] !== pairs[i][1]){
            return false;
          }
          
          var index2 = t.indexOf(pairs[i][1]);
          if(s[index2] !== pairs[i][0]){
            return false;
          }
        }
        
        
        return true;
      } else {
        return false;
      }
    
    };

Log in to reply
 

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