mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
12 lines
271 B
Python
12 lines
271 B
Python
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)
|
|
|