Skip to content

Commit 75939e5

Browse files
committed
feat: add two sum solution
1 parent 7ab60db commit 75939e5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

two-sum/mangodm-web.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def twoSum(self, nums: List[int], target: int) -> List[int]:
6+
index_map = {}
7+
8+
for i, n in enumerate(nums):
9+
complement = target - n
10+
11+
if complement in index_map:
12+
return [index_map[complement], i]
13+
index_map[n] = i

0 commit comments

Comments
 (0)