1. 两数之和

 

1. 两数之和

 

方法一

class Solution:
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        d = {}
        for i, num in enumerate(nums):
            a = nums[i]
            b = target - a
            if b in d:
                return [d[b], i]
            else:
                d[a] = i

  

posted @ 2019-01-18 11:24  小学弟-  阅读(114)  评论(0编辑  收藏  举报