Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input will have at most one solution, and you may not use the same index twice.
In case no solution exists, return [-1, -1]
Example:
Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]
Explanation: nums[0] + nums[1] = 2 + 7 = 9
Note:
Your algorithm should run in O(n^2) time and use O(1) space.
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check