2. 两数之和


Published: 周一 28 一月 2019

In Leetcode.

class Solution:
    def twoSum(self, nums, target):
        mp = {}
        for index, num in enumerate(nums):
            another_num = target - num
            if another_num in mp:
                return [mp[another_num], index]
            mp[num] = index