Two Sum
Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.
Constraints
- Each input has exactly one solution
- You may not use the same element twice
- Return the answer in any order
Examples
| Input | Target | Output |
|---|---|---|
[2, 7, 11, 15] | 9 | [0, 1] |
[3, 2, 4] | 6 | [1, 2] |
[3, 3] | 6 | [0, 1] |
Hint
Think about what complement you need for each number, and how to look it up in O(1).
Loading editor...
