Determine if the difference between an integer from the array and the target value exists
Linear Search Solution
def possibleSum1(array: list[int], target: int) -> bool:
# Linear Search Method
for i in range(len(array)):
current = array[i]
diff = target - current
# search diff from i+1 onwards
for j in range(i+1, len(array)):
if array[j] == diff:
return True
return FalseBinary Search Solution
Code Explanation
Function: possibleSum2
possibleSum2Last updated