Two Sum / Hashmap
Problem
Return indices of two numbers summing to a target.
Input / Output
- Input: an integer array
numsand an integertarget. - Output: the indices
[i, j]of the two numbers that add up totarget.
Constraints
- 2 ≤ n ≤ 10^4
- Exactly one valid pair is guaranteed.
Example
[2,7,11,15], 9 -> [0,1]
added …