[Leetcode by python] 1. Two Sum

题目

https://leetcode.com/problems/two-sum/
[Leetcode by python] 1. Two Sum

解题思路

第一次写技术博客,有点小兴奋!

代码

class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        d = {}
        for i in range(len(nums)):
            if target - nums[i] in d:
                return [d[target-nums[i]], i]
            d[nums[i]] = i