Simple Python Solution


  • 0
    class TwoSum(object):
    
        def __init__(self):
            self.h = {}
    
        def add(self, number):
            self.h[number] = self.h.get(number, 0) + 1
    
        def find(self, value):
            for x in self.h:
                if value-x in self.h and (value-x != x or self.h[x] > 1):
                    return True
            return False

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.