Two Sum
Return two distinct zero-based indices whose values sum to target. Either index order is allowed.
Example 1
nums = [4,8,2,7]
target = 11[0,3]Explanation
4 and 7 at indices 0 and 3 sum to 11.
Example 2
nums = [5,5]
target = 10[0,1]Explanation
The two separate occurrences of 5 sum to 10; one index cannot be used twice.
Example 3
nums = [-4,8,1]
target = -3[0,2]Explanation
-4 + 1 = -3, selecting indices 0 and 2.
Constraints
- 2 <= len(nums) <= 10000
- Exactly one index pair is a solution
- Values and target are signed 32-bit integers
Function contract
twoSumArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 49 cases, on your device.
[4,8,2,7]11