landscapemi的博客

# leetcode :Binary Search：Two Sum II - Input array is sorted(069)

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

http://www.cnblogs.com/grandyang/p/5185815.html

// O(n)
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
int l = 0, r = numbers.size() - 1;
while (l < r) {
int sum = numbers[l] + numbers[r];
if (sum == target) return {l + 1, r + 1};
else if (sum < target) ++l;
else --r;
}
return {};
}
};

#### 167. Two Sum II - Input array is sorted [medium] (Python)

2016-08-31 19:33:40

#### leetcode 167: Two Sum II - Input array is sorted

2014-12-31 08:27:56

#### LeetCode 167. Two Sum II - Input array is sorted 题解（C++）

2016-10-07 17:21:31

#### Leetcode-167. Two Sum II - Input array is sorted c语言

2016-09-01 20:42:00

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

2016-10-05 19:01:33

#### LeetCode Two Sum II - Input array is sorted(Two pointer问题)

2016-08-19 13:09:26

#### LeetCode(108)Convert Sorted Array to Binary Search Tree

2014-01-18 02:17:01

#### Search in Rotated Sorted Array II -- LeetCode

2014-03-06 02:04:55

#### Convert Sorted Array to Binary Search Tree -- LeetCode

2014-04-17 07:56:34

#### LeetCode OJ 108. Convert Sorted Array to Binary Search Tree DFS求解

2016-02-25 19:35:34