有人可以告诉我代码中的问题是什么。
这是问题: 给定一个整数数组,返回两个数字的索引,以便它们加起来成为一个特定的目标。
您可以假定每个输入都只有一个解决方案,并且您可能不会两次使用同一元素。
例:
给定nums = [2,7,11,15],目标= 9,
因为nums [0] + nums [1] = 2 + 7 = 9, 返回[0,1]。
class Solution(object):
def twoSum(self, nums`enter code here`, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
output = []
for i in range(0,len(nums)-1):
for j in range(0,len(nums)-1):
if i < j and (nums[i]+nums[j]==target):
output.append(i)
output.append(j)
print(output)