python: leetcode - 1 Two Sum

weixin_43012796發表於2020-12-13

在這裡插入圖片描述

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        value_container = {}
        for index, value in enumerate(nums):
            left_value = target - value
            if value in value_container:
                return [value_container[value], index]
            value_container[left_value] = index

相關文章