Create two_sums.py

This commit is contained in:
bt3gl 2023-07-30 13:56:04 -07:00 committed by GitHub
parent 48ce09742e
commit bc0d591be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,11 @@
def two_sum(nums: list[int], target: int) -> list[int]:
aux_dict = {}
for i, n in enumerate(nums):
complement = target - n
if complement in aux_dict:
return [aux_dict[complement][0], i]
aux_dict[n] = (i, n)