We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53ce7c7 commit 7c26d77Copy full SHA for 7c26d77
two-sum/prograsshopper.py
@@ -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