Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed May 28, 2023
1 parent daeda05 commit 3d06626
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function twoSum(numbers, target) {
let start = 0;
let end = numbers.length - 1;
let result = [];

while (start < end) {
let sum = numbers[start] + numbers[end];

if (sum === target) {
result.push(start + 1);
result.push(end + 1);
break;
}

if (sum > target) end--;
else start++;
}

return result;
}

0 comments on commit 3d06626

Please sign in to comment.