1.给定一个整数数组 nums
和一个目标值 target
,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
class Solution: def twoSum(self, nums, target): temp = {} try: for index,i in enumerate(nums): temp[index] = i print(temp) for key ,value in temp.items(): x = target - value if x in nums and nums.index(x)!=key: return key, nums.index(x) except: print('No two sum solution')
2.