Skip to content

Commit 59a5cfb

Browse files
committed
week1: two-sum
1 parent 038a0eb commit 59a5cfb

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

two-sum/reeseo3o.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const twoSum = (nums, target) => {
2+
const map = {};
3+
4+
for (let i = 0; i < nums.length; i++) {
5+
const complement = target - nums[i];
6+
7+
if (complement in map) {
8+
return [map[complement], i];
9+
}
10+
11+
map[nums[i]] = i;
12+
}
13+
};

0 commit comments

Comments
 (0)