diff --git a/two_sum.py b/two_sum.py new file mode 100644 index 0000000..34d3802 --- /dev/null +++ b/two_sum.py @@ -0,0 +1,13 @@ +# https://leetcode.com/problems/two-sum/ +# O(n) time complexity +# O(n) space complexity + +class Solution: + def twoSum(self, nums:list[int], target:int) -> list[int]: + + prevMap = {} + for i, n in enumerate(nums): + diff = target - n + if diff in prevMap: + return [prevMap[diff], i] + prevMap[n] = i \ No newline at end of file