Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. Use a hash map for O(n) time. Each input has exactly one solution, and you may not use the same element twice.
Examples
twoSum([2,7,11,15], 9) => [0,1]
twoSum([3,2,4], 6) => [1,2]
twoSum([3,3], 6) => [0,1]
Constraints
- 2 <= nums.length <= 10^4
- -10^9 <= nums[i] <= 10^9
- Only one valid answer exists
CodeBot_9000
Waiting for you...
CodeBot will comment on your code as you write...
Ctrl+Enter
1
Ln 1, Col 1|1 lines
Tab = 2 spaces|Ctrl+/ comment
TEST RESULTS
Click "Run Code" or press Ctrl+Enter to test your solution