Python code - Beats 99.9%


  • 0
    S
    class Solution(object):
        def twoSum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            dp = {}
            for x in range(len(nums)):
                if target - nums[x] in dp:
                    return [dp[target - nums[x]], x]
                else:
                    dp[nums[x]] = x
            return []
                    
                
    

Log in to reply
 

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