simple Javascript code

  • 1

    I am not a big fan of Javascript, but I'm currently server-side programmer.
    So what I'm doing is migrating my c++ code to Javascript code.

    var twoSum = function(nums, target) {
      var map = new Map();
      for(var i = 0; i<nums.length; i++) {
          var num = nums[i];
          if(map.get(num) === undefined) map.set(target-num, i);
          else return [map.get(num), i];

Log in to reply

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