mycode  33.91%

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums)):
            temp = target - nums[i]  
            if temp in nums[i+1:]:
                return [i,nums[i+1:].index(temp)+i+1]

参考:

def two_sum(myList,target):
    d = {}
    for i,num in enumerate(myList):
        print('...',i,target-num)
        if target - num in d:
            print('true')
            print('...',i,target-num,d[target-num])
            return [d[target-num],i]
        d[num] = i
        print(d)
myList = [2,7,11,15,6]
print(two_sum(myList,22))