My solution for the Two Sum
liste = [1, 2, 3, 5, 7, 4]
target = 10
def twoSum (liste, target):
index = []
for num in liste:
i = liste.index(num)
rest = target - num
indexlist = [id for id in range(len(liste))]
indexlist.remove(i)
for n in indexlist:
if rest == liste[n]:
index.append(i)
index.append(n)
indexlist = [id for id in range(len(liste))]
return index
return -1
twoSum(liste, target)
[2, 4]
0 answers ( 0 marked as helpful)