Skip to content

Commit 2f26845

Browse files
committed
1 parent b5a1430 commit 2f26845

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/two-sum.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target.
3+
*
4+
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
5+
*
6+
* two0sum.js
7+
*
8+
* @param {number[]} nums
9+
* @param {number} target
10+
* @return {number[]}
11+
*/
12+
let twoSum = function(nums, target) {
13+
for (let i = nums.length - 1; i >= 0; i--) {
14+
for (let j = 0; j < i; j++) {
15+
if ( addition(nums[i], nums[j]) === target ) {
16+
return [j, i];
17+
}
18+
}
19+
}
20+
};
21+
22+
// add a with b and return it
23+
let addition = function(a, b) {
24+
return a + b;
25+
};

0 commit comments

Comments
 (0)