Skip to content

Commit 2b60712

Browse files
committed
Added the solution of Two Sum in OtherAlgorithm Folder
1 parent 5614404 commit 2b60712

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎OtherAlgorithms/TwoSum.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var twoSum = function (num, tar) {
2+
var res = [];
3+
4+
for (var i = 0; i < num.length; i++) {
5+
for (var j = i + 1; j < num.length; j++) {
6+
if (num[i] + num[j] === tar) {
7+
res.push(i);
8+
res.push(j);
9+
}
10+
}
11+
}
12+
return res;
13+
}
14+
15+
console.log(twoSum([2, 7, 11, 15], 9));
16+
// Output [ 0, 1 ]

0 commit comments

Comments
 (0)