[
2sum
hash table
]
BinarySearch 0001 Sum of Two Numbers
Problem statement
https://binarysearch.com/problems/Sum-of-Two-Numbers/
Solution
Classical 2sum problem, almost equal to leetcode 0001 2sum
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, nums, k):
s = Counter(nums)
for x in s:
if (k - x in s and x*2 != k) or (s[x] >= 2 and x*2 == k):
return True
return False