# leetcode167

1、Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, 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

class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
vector<int> result;
int length=numbers.size();
int low=0,high=length-1;
while(low<=high){
if(numbers[high]+numbers[low]<target)
++low;
else if(numbers[high]+numbers[low]>target)
--high;
else{
result.push_back(low+1);
result.push_back(high+1);
break;
}
}
return result;
}
};

#### LeetCode 167.Two Sum II 解题报告

2016-09-18 13:43:00

#### leetcode【1+167 Two Sum 系列】【python】

2016-09-01 19:31:36

#### LeetCode oj 167. Two Sum II - Input array is sorted （双指针）

2016-10-05 19:01:33

#### LeetCode167 and 1 Two Sum

2018-03-15 21:11:32

#### leetcode167 Two SumII java

2017-03-09 10:49:49

#### Leetcode167: Bitwise AND of Numbers Range

2015-11-24 21:04:09

#### leetcode167: Two Sum II - Input array is sorted

2017-04-06 19:24:04

#### Add Binary | leetcode 67 【Java解题报告】

2015-10-04 14:23:39

#### leetcode167~Two Sum II - Input array is sorted

2017-03-09 10:52:30

#### LeetCode167—Two Sum II - Input array is sorted

2016-11-23 09:31:15