Skip to content

力扣p1

python
class Solution(object):  
    def twoSum(self, nums, target):  
        """  
        :type nums: List[int]  
        :type target: int  
        :rtype: List[int]  
        """  
        # 字典
        lookup = {}  
        for i, num in enumerate(nums):  
            temp = target - num  
            if temp in lookup:  
                return [lookup[temp], i]  
            lookup[num] = i