Python solution, 6 lines


  • 0
    W
    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]
                else:
                    d[num] = i
    

Log in to reply
 

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