Sum of Two Numbers
easySave
ArrayMath
Given an array of integers and a target number, determine if there are two distinct numbers in the array that sum up to the target number. Return true if such a pair exists and false otherwise.
Example 1
Input
[ [ 10, 15, 3, 7 ], 17 ]
Output
true
Explanation. 10 and 7 sum up to 17.
Example 2
Input
[ [ 10, 15, 3, 4 ], 17 ]
Output
false
Explanation. There are no two numbers in the array that can sum up to 17.
Example 3
Input
[ [ 2, 5, 1, -10, 7 ], -5 ]
Output
true
Explanation. -10 and 5 sum up to -5.
Follow-up: Can you implement the solution to have a linear time complexity, i.e., O(n)?
Constraints:
The input array will contain at least two numbers. All elements and the target number will be integers.
- Views
- 3