Given an array of integers numbers
and an integer target
, return indices of the two numbers such that they add up to target
. You may assume that each input would have exactly one solution, and you may not use the same element twice (leetcode "two-sum" task)
Input 1:
const numbers1 = [3, 2, 4];
const target1 = 6;
twoSum(numbers, target);
Output 1:
[ 1, 2 ]
Input 2:
const numbers = [-2, 1, 7, 3, 10];
const target = 5;
twoSum(numbers, target);
Output 2:
[ 0, 2 ]
Input 3:
const numbers = [5, 5];
const target = 10;
twoSum(numbers, target);
Output 2:
[ 0, 1 ]