Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2
中文解释:
现在咱们给你一个整形的数组,再给你一个目标值,需要你从咱们给你的整形数组里面找到相加和等于目标值的两个数。
功能函数twoSum应该返回那两个数的索引值,但是请你记住,你返回的索引值index1必须小于index2,还有请你记住,你返回的答案是从一开始的(不要从0开始计数)
当然了,你可以假设我们给你的每个输入值肯定能得到目标值。
输入:numbers={2, 7, 11, 15}, target=9
输出:index1=1, index2=2