Two Sum II - Input Array is Sorted

Given a sorted array of integers `nums` and a target integer `target`, return `true` if there exist two numbers in the array such that they add up to `target`, otherwise return `false`.

Input Format

nums = array of integers (sorted), target = target sum to find

Output Format

true if a valid pair exists, false otherwise

Constraints

Examples

Example 1:

Input:

nums = [1,2,3,4,6]
target = 6

Output:

[2,4]

Explanation:

1 + 5 = 6 exists.

Example 2:

Input:

nums = [2,5,9,11]
target = 7

Output:

[1,2]

Explanation:

No two numbers sum to 7.

Example 3:

Input:

nums = [-3,-1,0,1,2]
target = -2

Output:

[1,4]

Explanation:

-3 + 1 = -2 exists.

Loading...
Two Sum II - Input Array is Sorted