mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 16:31:15 -04:00
Create two_sums.py
This commit is contained in:
parent
48ce09742e
commit
bc0d591be1
1 changed files with 11 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue