Two Sum
Easy
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
Constraints
- 2 <= nums.length <= 10^4
- -10^9 <= nums[i] <= 10^9
- -10^9 <= target <= 10^9
- Only one valid answer exists.
Example
Input: nums = [2,7,11,15], target = 9
Expected Output: [0,1]
Edge Cases
- An array where the solution uses two identical values (e.g., [3, 3] and target = 6). The values are the same, but indices must be different.
- An array containing negative numbers. The target may be formed using negative values.
- An array containing zero. Zero can be part of the answer.