leecode-两数之和(简单)
给定一个整数数列,找出其中和为特定值的那两个数。
你可以假设每个输入都只会有一种答案,同样的元素不能被重用。
示例:
给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1]
示例:
找一个然后判断另一个在不在列表里就好了
1 for num in nums: 2 if num*2 == target and nums.count(num)==1: 3 continue; 4 if (target-num) in nums: 5 temp = nums.index(num) 6 return( list((temp,nums[temp+1:].index(target-num)+temp+1)))