Two Sum
Problem Given an array of integers and a target value, return the indices of the two numbers that add up to the target. Exactly one valid pair is guaranteed, and the same element may not be used twice.
Input / Output
- Input: integer array
numsand integertarget. - Output: a pair of indices
[i, j]withnums[i] + nums[j] == target.
Constraints
2 <= nums.length <= 10^4- Exactly one solution exists.
- Values may be negative; a value may repeat.
Example
nums = [2,7,11,15], target = 9->[0,1]nums = [3,3], target = 6->[0,1]
added …