Python solution, 6 lines

  • 0
    class Solution(object):
        def twoSum(self, nums, target):
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            d = {}
            for i, num in enumerate(nums):
                if d.get(target - num) != None:
                    return [d[target - num], i]
                    d[num] = i

Log in to reply

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