6
0
:0
0
Two Prices, One Receipt
Two Prices, One Receipt
Easy
Hash
In "Two Prices, One Receipt", you are given a list of integer values and a target total. Find the two different positions whose values add up to the target.
Return the two indices in any order. You may assume there is exactly one valid answer.
Example 1
Input:
nums = [4,9,15,6,24], target = 10Output:
[0,3]For input nums = [4,9,15,6,24], target = 10, Indices [0,3] are correct because nums[0] + nums[3] = 4 + 6 = 10. Therefore, return [0,3].
Example 2
Input:
nums = [7,8,12,12,13], target = 20Output:
[1,2]For input nums = [7,8,12,12,13], target = 20, Indices [1,2] are correct because nums[1] + nums[2] = 8 + 12 = 20. Therefore, return [1,2].
Constraints
2 <= nums.length <= 104-109 <= nums[i] <= 109-109 <= target <= 109Exactly one valid pair exists.
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[4,9,15,6,24], 10Expected Output:
[0,3]Test Case 2
Input:
[7,8,12,12,13], 20Expected Output:
[1,2]