1.两数之和
给定一个整数数组nums和一个目标值target,请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下标。
def twoSum(self, nums: List[int], target: int) -> List[int]:
j = -1
for i in range(1,len(nums)):
temp = nums[:i]
if(target-nums[i]) in temp:
j = temp.index(target - nums[i])
break
if j >= 0:
return [j,i]