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 daa942f commit 89b1809Copy full SHA for 89b1809
two-sum/bemelon.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ # Space complexity: O(n)
3
+ # Time complexity: O(n)
4
+ def twoSum(self, nums: list[int], target: int) -> list[int]:
5
+ num_index = {}
6
+ for curr, num in enumerate(nums):
7
+ rest = target - num
8
+ if rest in num_index:
9
+ return [num_index[rest], curr]
10
+ else:
11
+ num_index[num] = curr
12
+ return [0, 0]
13
+
0 commit comments