From 59dff1b261a6489dab5e487f311d897910c4bf5c Mon Sep 17 00:00:00 2001 From: Rodolfo P A <6721075+rodoufu@users.noreply.github.com> Date: Wed, 8 Jul 2026 12:51:28 -0300 Subject: [PATCH] Create two-sum.py --- leetCode/array/two-sum.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 leetCode/array/two-sum.py diff --git a/leetCode/array/two-sum.py b/leetCode/array/two-sum.py new file mode 100644 index 0000000..a0c9fc4 --- /dev/null +++ b/leetCode/array/two-sum.py @@ -0,0 +1,15 @@ +# https://leetcode.com/problems/two-sum/ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + num_index = {} + for i in range(len(nums)): + num_index[nums[i]] = i + + for i in range(len(nums)): + num = nums[i] + other = target - num + other_index = num_index.get(other) + if other_index and other_index != i: + return [i, other_index] + + return []