Find Indices of Elements for Sum
Avito
You need to write a function twoSum(nums, target) that takes an array of numbers
nums and a number target.
The function should return an array with two indices of elements whose sum equals target.
It is guaranteed that there is always exactly one solution.Examples:
Input 1: [3, 3], 6
Output 1: [0, 1]
Input 2: [2, 7, 11, 5, 9, 10, 15], 9
Output 2: [0, 1]
JavaScript•UTF-8
Run your code to see results.
Click the Run button above
Find Indices of Elements for Sum
Avito
You need to write a function twoSum(nums, target) that takes an array of numbers
nums and a number target.
The function should return an array with two indices of elements whose sum equals target.
It is guaranteed that there is always exactly one solution.Examples:
Input 1: [3, 3], 6
Output 1: [0, 1]
Input 2: [2, 7, 11, 5, 9, 10, 15], 9
Output 2: [0, 1]
Run your code to see results.