Skip to content

Commit e0d1897

Browse files
committed
tow sum
1 parent d16f512 commit e0d1897

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

two-sum/jihyeon.js

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

0 commit comments

Comments
 (0)