22 5 月 2020

leetcode第一题解法2

原题https://leetcode.com/problems/two-sum/

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        st={}
        ac=[]
        for i,val in enumerate(nums):
            if val in st:
                ac.append(st[val])
                ac.append(i)
                return ac
            else:
                st[target-val]=i