Arrays


Arrays

Two Sums

class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        complement_index = {}

        for i, n in enumerate(nums):
            print(i, n)
            complement = target - n
            print(complement)
            complement_index[complement] = i

        for i, n in enumerate(nums):
            if n in complement_index and i != complement_index[n]:
                print(n)
                return [i, complement_index[n]]