79. Two Sum II - Input Array Is Sorted

MediumArrayArray

Given a 1-indexed sorted array numbers, find two numbers that add up to target. Return [index1, index2] (1-indexed). Exactly one solution exists.

Input: Sorted integer array numbers and integer target.

Output: [index1, index2] (1-indexed).

Examples

Example 1
Input: [2,7,11,15],9
Output: [1,2]
Explanation: 2+7=9.
Example 2
Input: [2,3,4],6
Output: [1,3]
Explanation: 2+4=6.
Example 3
Input: [-1,0],-1
Output: [1,2]
Explanation: -1+0=-1.

Constraints

Asked by

AmazonGoogleMicrosoftBloombergMetaApple
Solve this problem in the editor →