Skip to content

Commit 67bf347

Browse files
Suraj RajasekharSuraj Rajasekhar
authored andcommitted
TwoSum.js
1 parent 02fde65 commit 67bf347

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

javascript/Twosum.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} target
4+
* @return {number[]}
5+
*/
6+
var twoSum = function(nums, target) {
7+
let map = {};
8+
for(let i=0; i<nums.length; i++){
9+
if (map[target-nums[i]] !== undefined)
10+
return [i, map[target-nums[i]]];
11+
else
12+
map[nums[i]]=i;
13+
}
14+
return [];
15+
};

0 commit comments

Comments
 (0)