Two Sum II Input Array Is Sorted
In a nondecreasing integer array, return the two distinct one-based indices whose values sum to target. Use constant auxiliary space.
Example 1
numbers = [-3,0,4,9]
target = 6[1,4]Explanation
-3 + 9 = 6; zero-based positions 0 and 3 become one-based indices 1 and 4.
Example 2
numbers = [2,2]
target = 4[1,2]Explanation
The separate 2 occurrences give one-based indices 1 and 2.
Example 3
numbers = [1,4,6,10]
target = 10[2,3]Explanation
4 + 6 = 10, selecting one-based indices 2 and 3.
Constraints
- 2 <= len(numbers) <= 30000
- Exactly one pair exists
Function contract
twoSumArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[-3,0,4,9]6