Skip to content

Commit f7540e3

Browse files
committed
two sum solution
1 parent a7426ad commit f7540e3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

two-sum/doh6077.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def twoSum(self, nums: list[int], target: int) -> list[int]:
3+
prevMap = {} # val : index
4+
for i, n in enumerate(nums):
5+
diff = target - n
6+
if diff in prevMap:
7+
return [prevMap[diff], i]
8+
prevMap[n] = i

0 commit comments

Comments
 (0)