55: Two sum
Given an array of integers
and sum
, return indices
of numbers whose sum is equal
to the given sum
Note: Each integer can be used
only once
and the input hasexactly
one solution
Example 1
Input: array = [2, 1, 4, 9, 0], sum = 5
Output: [1, 2]
Explanation:
array[1]
+array[2]
= 5
Example 2
Input: array = [-2, 1, 4, 2, 10], sum = 0
Output: [0, 3]