Two Sum II - Input Array Is Sorted

Given a 1-indexed array of integers numbers that is sorted in non-decreasing order, find two distinct numbers that add up to a specific target number and return their indices as an array. The problem guarantees that there is exactly one solution and the solution should use constant extra space.

Constraints

  • 2 <= numbers.length <= 30000
  • -1000 <= numbers[i] <= 1000
  • numbers is sorted in non-decreasing order
  • -1000 <= target <= 1000
  • There is exactly one solution
Saving… · 2 lines
class Solution:
def twoSumII(self, numbers: List[int], target: int) -> List[int]:
Console

Click Run to execute sample tests.