Asked at
Two Sum
EasyVerifiedArrayHash Map~15 min
Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.
You may assume each input has exactly one solution, and you may not use the same element twice. Return the answer in any order.
The input arrives as a single object { nums, target }.
Examples
in{ nums: [2, 7, 11, 15], target: 9 }
out[0, 1]
nums[0] + nums[1] == 9.
in{ nums: [3, 2, 4], target: 6 }
out[1, 2]
nums[1] + nums[2] == 6.
Constraints
- 2 ≤ nums.length ≤ 10⁴
- -10⁹ ≤ nums[i] ≤ 10⁹
- Exactly one valid answer exists.
Get help
🔑
Sign in to solve
Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.