# 167. 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

My code:

class Solution(object):
def twoSum(self, numbers, target):
"""
:type numbers: List[int]
:type target: int
:rtype: List[int]
"""
n = len(numbers)
low = 0
high = n-1
sums=numbers[low]+numbers[high]
while sums!=target:
if sums >target:
high -=1
else:
low +=1
sums=numbers[low]+numbers[high]
return low+1, high+1

#### 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

2014-12-31 08:27:56

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

2016-09-01 20:42:00

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

2016-08-31 19:33:40

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

2016-10-05 19:01:33

#### LeetCode-Easy部分中标签为 Binary Search 167. Two Sum II - Input array is sorted

2017-04-08 22:20:20

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

2016-08-19 13:09:26

#### leetcode_167. Two Sum II - Input array is sorted 有序数组中找和为特定数的两个数的下标

2016-11-12 22:05:52

#### 【LeetCode】167. Two Sum II - Input array is sorted

2016-08-18 23:05:19

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

2016-09-18 13:43:00