Given an array of integers numbers
, write a function that returns the indices of two integers within the numbers
array that sum up to a target
integer. The smaller index should appear first.
numbers: number[]
: An array of integerstarget: number
: An integerInput: numbers = [0,7,1,9], target = 7Output: [0,1]Explanation: numbers[0] plus numbers[1] = 7 which is target
Input: numbers = [4,9,2,1,7], target = 5Output: [0,3]Explanation: numbers[3] plus numbers[0] = 5 which is target
Input: numbers = [4,4], target = 8Output: [0,1]Explanation:
numbers.length
<= 100numbers[i]
<= 1000target
<= 1000Given an array of integers numbers
, write a function that returns the indices of two integers within the numbers
array that sum up to a target
integer. The smaller index should appear first.
numbers: number[]
: An array of integerstarget: number
: An integerInput: numbers = [0,7,1,9], target = 7Output: [0,1]Explanation: numbers[0] plus numbers[1] = 7 which is target
Input: numbers = [4,9,2,1,7], target = 5Output: [0,3]Explanation: numbers[3] plus numbers[0] = 5 which is target
Input: numbers = [4,4], target = 8Output: [0,1]Explanation:
numbers.length
<= 100numbers[i]
<= 1000target
<= 1000console.log()
语句将显示在此处。