leetcode1 python3 76ms twoSum 360面试题

class Solution:
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        d = {}
        for i in range(0, len(nums)):
            if target - nums[i] not in d.keys():
                d[target - nums[i]] = i
            if nums[i] in d.keys() and i !=d[nums[i]]:
                return [d[nums[i]], i]
         
posted @ 2018-08-04 23:46  一条图图犬  阅读(148)  评论(0编辑  收藏  举报