Why my JavaScript solution doesn't accepted but the same code on Ruby works fine?


  • 0
    M
    var TwoSumFastWrite = function() {
      this.nums = {};
    };
    
    TwoSumFastWrite.createNew = function() {
      return new TwoSumFastWrite();
    }
    
    TwoSumFastWrite.prototype.add = function(number) {
      this.nums[number] = this.nums[number] ? this.nums[number] + 1 : 1;
    };
    
    TwoSumFastWrite.prototype.find = function(value) {
      var keys = Object.keys(this.nums);
      var result = false;
    
      for(var i = 0; i < keys.length; i ++) {
        var key = Number(keys[i]);
    
        if(this.nums[value - key] && value - key !== key || this.nums[value - key] == 2) {
          result = true;
          break;
        }
      }
    
      return result;
    };
    

Log in to reply
 

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