Last answered:

09 Nov 2024

Posted on:

27 Jul 2023

2

an alternate soln to the TWO SUMPROBLEM


def twosum(L, target):
    for i in range(len(L)):
        for j in range(i + 1, len(L)):
            if L[i] + L[j] == target:
                return i, j
    return -1

print(twosum([2, 5, 3, 7, 9], 10))

2 answers ( 0 marked as helpful)
Posted on:

12 Oct 2023

3

this works, but i think it is a brute force method as explained by Giles in the beginning on paper.

Posted on:

09 Nov 2024

0
Yes, it's brute force and it's not recommended.

Submit an answer