Skip to content

Commit 7c26d77

Browse files
week 1: two sum
1 parent 53ce7c7 commit 7c26d77

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

two-sum/prograsshopper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def twoSum(self, nums: List[int], target: int) -> List[int]:
3+
index_dict = {elem: idx for idx, elem in enumerate(nums)}
4+
result = []
5+
for idx, num in enumerate(nums):
6+
remain = index_dict.get(target-num, None)
7+
if remain and idx != remain:
8+
result = [idx, remain]
9+
break
10+
return result

0 commit comments

Comments
 (0)