Two Sum (Sorted Array)

Arrays & Two-Pointers · easy

Given a **sorted** array `nums` and a `target`, return the 0-based indices `[i, j]` of the two numbers that add up to `target`. Exactly one solution exists. Example: `twoSum([1, 2, 4, 7], 6)` → `[1, 2]`.

Hints
  • Start one pointer at the left end and one at the right end.
  • If the sum is too large, move the right pointer left; if too small, move the left pointer right.

Learning resources

Loading...

Run your code to see results.