mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
17 lines
336 B
Python
17 lines
336 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
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)
|
|
|