6
0
:0
0
Two Prices, One Receipt: Server Cost Edition
Two Prices, One Receipt: Server Cost Edition
Easy
Hash
In "Two Prices, One Receipt: Server Cost Edition", 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 = [24,29,35,26,44], target = 50Output:
[0,3]For input nums = [24,29,35,26,44], target = 50, Indices [0,3] are correct because nums[0] + nums[3] = 24 + 26 = 50. Therefore, return [0,3].
Example 2
Input:
nums = [27,48,32,72,33], target = 80Output:
[1,2]For input nums = [27,48,32,72,33], target = 80, Indices [1,2] are correct because nums[1] + nums[2] = 48 + 32 = 80. 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:
[24,29,35,26,44], 50Expected Output:
[0,3]Test Case 2
Input:
[27,48,32,72,33], 80Expected Output:
[1,2]