问题描述:
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。
你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。
def twoSum( nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
for i in range(len(nums)):
othernums = target - nums[i]
if othernums in nums[i+1:]:#排除
j=nums[i+1:].index(othernums)
j=j+i+1
return [i,j]