easy
Two Sum II — Sorted Input
Given an array of integers sorted in non-decreasing order and a target, return the 1-based indices of the two elements that sum to the target. Exactly one solution exists and you must use only constant extra space.
Constraints
- 2 ≤ n ≤ 3 · 10^4
- -1000 ≤ numbers[i], target ≤ 1000
- Exactly one solution
Examples
in: numbers = [2,7,11,15], target = 9
out: [1, 2]
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.