Two Sum II - Input Array Is Sorted
Medium
Topics
Given a 1-indexed array numbers sorted in non-decreasing order, find two numbers adding up to target. Return [index1, index2] (1-indexed) with index1 < index2.
Exactly one solution exists; use only constant extra space.
Example 1
Input: numbers = [2,7,11,15], target = 9 Output: [1,2]
Example 2
Input: numbers = [2,3,4], target = 6 Output: [1,3]
Constraints
- 2 <= numbers.length <= 3*10^4
- numbers is sorted non-decreasing.
- Exactly one solution.
Run ⌘' · Submit ⌘⏎