From bc0d591be192c9416f8b7a572081630215b28cc0 Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-google@users.noreply.github.com> Date: Sun, 30 Jul 2023 13:56:04 -0700 Subject: [PATCH] Create two_sums.py --- arrays_and_strings/two_sums.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 arrays_and_strings/two_sums.py diff --git a/arrays_and_strings/two_sums.py b/arrays_and_strings/two_sums.py new file mode 100644 index 0000000..9f8b32f --- /dev/null +++ b/arrays_and_strings/two_sums.py @@ -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) +