left
at the start of the array and right
at the end of the array.left
is less than right
:
a. Calculate the sum of numbers[left]
and numbers[right]
.
b. If the sum is equal to the target, return [left + 1, right + 1]
as the result (since the array is 1-indexed).
c. If the sum is less than the target, increment left
to move towards a larger sum.
d. If the sum is greater than the target, decrement right
to move towards a smaller sum.