8000 first commit · Omny/.leetcode@f9cdba0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9cdba0

Browse files
committed
first commit
0 parents  commit f9cdba0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

1.two-sum.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @lc app=leetcode id=1 lang=javascript
3+
*
4+
* [1] Two Sum
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* @param {number[]} nums
10+
* @param {number} target
11+
* @return {number[]}
12+
*/
13+
var twoSum = function (nums, target) {
14+
const map = new Map();
15+
for (let index = 0; index < nums.length; index += 1) {
16+
const num = nums[index];
17+
const numToFind = target - num;
18+
const index2 = map.get(numToFind);
19+
if (index2 !== undefined) {
20+
return [index2, index];
21+
}
22+
map.set(num, index);
23+
}
24+
return null;
25+
};
26+
// @lc code=end

0 commit comments

Comments
 (0)
0