diff --git a/LeetCode/Problems/Python/2_Two_Sum.py b/LeetCode/Problems/Python/2_Two_Sum.py new file mode 100644 index 00000000..3bbfc6b3 --- /dev/null +++ b/LeetCode/Problems/Python/2_Two_Sum.py @@ -0,0 +1,12 @@ +class Solution: + def twoSum(self, nums, target): + targets_dict = {} + + for i, num in enumerate(nums): + if(num in targets_dict): + return [targets_dict[num], i] + targets_dict[target-num] = i + + # we do not need to return because we assume that + # we have exactly one solution + # return -1