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‘)
原文:https://www.cnblogs.com/dolphin-bamboo/p/10457284.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!