We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8e2d578 commit 5bfb9b7Copy full SHA for 5bfb9b7
1-Two-Sum.py
@@ -0,0 +1,9 @@
1
+class Solution:
2
+ def twoSum(self, nums: List[int], target: int) -> List[int]:
3
+ prevMap = {} # val -> index
4
+
5
+ for i, n in enumerate(nums):
6
+ diff = target - n
7
+ if diff in prevMap:
8
+ return [prevMap[diff], i]
9
+ prevMap[n] = i
0 commit comments