Two Sum
Problem
Return the indices of the two numbers in nums that add up to target. Exactly one valid answer exists, and an element may not be used twice.
Input / Output
- Input: integer array
nums, integertarget. - Output: the pair of indices
[i, j]withnums[i] + nums[j] == target.
Constraints
- 2 ≤ nums.length ≤ 10^4
- Values may be negative and may repeat.
Example
- nums = [3,2,4], target = 6 → [1,2].
- nums = [3,3], target = 6 → [0,1].
added …