Skip to content

Commit 8f5e2d1

Browse files
TemitopeAgbajeignacio-chiazzo
authored andcommitted
updated 2sum
1 parent 24d0ef3 commit 8f5e2d1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

LeetcodeProblems/Algorithms/2Sum.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ var twoSum = function (nums, target) {
3838
map[nums[i]] = i;
3939
}
4040
}
41+
};
4142

42-
//Another method
43-
43+
//Another method
44+
var twoSum2 = function (nums, target) {
4445
for (let i = 0; i < nums.length; i++) {
4546
for (let j = i + 1; j < nums.length; i++) {
4647
if (nums[1] + nums[j] === target) {
@@ -51,3 +52,4 @@ var twoSum = function (nums, target) {
5152
};
5253

5354
module.exports.twoSum = twoSum;
55+
module.exports.twoSum2 = twoSum2;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
const assert = require("assert");
22
const twoSum = require("../../LeetcodeProblems/Algorithms/2Sum").twoSum;
3+
const twoSum2 = require("../../LeetcodeProblems/Algorithms/2Sum").twoSum2;
34

45
var test = function () {
56
assert.deepEqual([0,1], twoSum([2,7,11,15], 9));
67
assert.deepEqual([1,2], twoSum([3,2,4], 6));
78
assert.deepEqual([0,1], twoSum([3,3], 6));
89
};
910

11+
var test2 = function () {
12+
assert.deepEqual([0,1], twoSum2([2,7,11,15], 9));
13+
assert.deepEqual([1,2], twoSum2([3,2,4], 6));
14+
assert.deepEqual([0,1], twoSum2([3,3], 6));
15+
};
16+
1017
module.exports.test = test;
18+
module.exports.test2 = test2;
1119

0 commit comments

Comments
 (0)