Two Sum and Variations
09 May 2022
Given an array of integers numbers
, return the indices of the two integers that add up to target
.
How to solve it when the array is sorted? The following code shows a two pointers approach to solve the problem when the array is sorted.
There are other variations of the problem. For example, the problem can ask to find 3 or 4 numbers that add up to traget.