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 8f7a714 commit c1c5103Copy full SHA for c1c5103
two-sum/jiunshinn.py
@@ -0,0 +1,12 @@
1
+# time complexity : o(n)
2
+# space complexity : o(n)
3
+class Solution:
4
+ def twoSum(self, nums: List[int], target: int) -> List[int]:
5
+ hashmap = {}
6
+
7
+ for i, n in enumerate(nums):
8
+ diff = target - n
9
+ if diff in hashmap:
10
+ return [i, hashmap[diff]]
11
+ else:
12
+ hashmap[n] = i
0 commit comments