Skip to content

Commit 5bfb9b7

Browse files
authored
Create 1-Two-Sum.py
1 parent 8e2d578 commit 5bfb9b7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

1-Two-Sum.py

+9
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)