6-line Simple Python Solution

  • 1
    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]
                    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.