Skip to content

Commit a07a75d

Browse files
author
baochau.dinh
committed
js-concepts: leetcode prob.1 - two sum
1 parent 0a0ef4c commit a07a75d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

LeetCode/1. Two Sum/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var twoSum = function(nums, target) {
2+
let hashSet = new Set();
3+
for (let i = 0; i < nums.length; i++) {
4+
if (hashSet.has(target - nums[i])) {
5+
return [i, nums.indexOf(target - nums[i])];
6+
} else {
7+
hashSet.add(nums[i]);
8+
}
9+
}
10+
};

0 commit comments

Comments
 (0)