francistao / LearningNotes

Enjoy Learning.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

two-sum理解题目有误

anderswhz opened this issue · comments

LearningNotes/Part3/Algorithm/LeetCode/two-sum.md

题目的意思应该是:一个整数数组,找到2个数字,他们的和正好为一特定的数。功能是返回这两个数字的对应索引号。index1必须小于index2,而且回答的index不是从0开始的。

thanks

Question

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
题目大意:

给定一个整数数组,找到2个数字,这样他们就可以添加到一个特定的目标号。功能twosum应该返回两个数字,他们总计达目标数,其中index1必须小于index2。请注意,你的答案返回(包括指数和指数)不为零的基础。你可以假设每个输入都有一个解决方案。
输入数字numbers= { 2,7,11,15 },目标= 9输出:index1 = 1,index2= 2