Skip to content

Commit afd91e5

Browse files
committed
Delete 0001 Solution2.js and Solution3.js, Update 0001 Solution.js
1 parent 4cb69ba commit afd91e5

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

solution/0001.Two Sum/Solution.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
1+
/**
2+
* Author: limbowandering
3+
*/
4+
15
const twoSum = function(nums, target) {
26
const map = {};
3-
47
for (let i = 0; i < nums.length; i++) {
58
if (map[nums[i]] !== undefined) {
69
return [map[nums[i]], i]
710
} else {
811
map[target - nums[i]] = i
912
}
1013
}
14+
};
15+
16+
/**
17+
* Author: Mcnwork2018
18+
*/
19+
20+
var twoSum = function(nums, target) {
21+
let len = nums.length;
22+
let n = {};
23+
for (let i = 0; i < len; i++) {
24+
if (n[target - nums[i]] !== undefined) {
25+
return [n[target - nums[i]], i];
26+
}
27+
n[nums[i]] = i;
28+
}
29+
};
30+
31+
/**
32+
* Author: rookie
33+
*/
34+
35+
var twoSum = function(nums, target) {
36+
const map = new Map();
37+
for (let i = 0; i < nums.length; i++) {
38+
if (map.has(target - nums[i])) {
39+
return [ map.get(target - nums[i]), i ]
40+
}
41+
map.set(nums[i], i);
42+
}
1143
};

solution/0001.Two Sum/Solution2.js

-10
This file was deleted.

solution/0001.Two Sum/Solution3.js

-9
This file was deleted.

0 commit comments

Comments
 (0)