Skip to content

Commit 9e95284

Browse files
committed
Merge branch 'master' of github.com:swiftwind0405/leetcode
2 parents 9c027a8 + 14a85a0 commit 9e95284

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

algorithms/2Sum/2Sum.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var twoSum = function (nums, target) {
2+
const map = new Map();
3+
const len = nums.length;
4+
5+
for (var i = 0; i < len; i++) {
6+
var diff = target - nums[i];
7+
if (map.has(diff) && i !== map.get(diff)) {
8+
return [i, map.get(diff)]
9+
}
10+
map.set(nums[i], i);
11+
}
12+
}

0 commit comments

Comments
 (0)