Pair Sum to Target
easySave
ArrayHash TableTwo Pointers
Given an array of integers and a target integer, determine if there are two distinct numbers in the array that sum up to the target number. Return true if such a pair exists, otherwise return false.
Example 1
Input
[ [ 10, 15, 3, 7 ], 17 ]
Output
true
Explanation. The numbers 10 and 7 sum up to the target number 17.
Example 2
Input
[ [ 1, 2, 3, 9 ], 8 ]
Output
false
Explanation. No two numbers sum up to the target number 8.
Example 3
Input
[ [ 1, 21, -3, 5 ], 2 ]
Output
true
Explanation. The numbers -3 and 5 sum up to the target number 2.
Follow-up: Can you solve the problem in linear time complexity?
Constraints:
- The numbers in the array and the target can be both positive and negative integers. - The array will contain at least two elements.
- Views
- 4