mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create two_sums.py
This commit is contained in:
parent
48ce09742e
commit
bc0d591be1
11
arrays_and_strings/two_sums.py
Normal file
11
arrays_and_strings/two_sums.py
Normal 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user