Skip to content

Commit 67cd52e

Browse files
committed
two-sum solution
1 parent 84d172b commit 67cd52e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

two-sum/krokerdile.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 dict = new Map();
8+
9+
for(const [index, num] of nums.entries()){
10+
if(dict.has(target-num) && dict.get(target-num) != index){
11+
return [dict.get(target-num),index];
12+
}
13+
dict.set(num, index);
14+
}
15+
};

0 commit comments

Comments
 (0)