6-line Simple Python Solution


  • 1
    M
    class Solution(object):
        def twoSum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            n, d = len(nums), {}
            for i in xrange(n):
                if nums[i] in d:
                    return [d[nums[i]], i]
                else:
                    d[target - nums[i]] = i
    
    

Log in to reply
 

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