Skip to content

Commit c1c5103

Browse files
committed
two sum solution
1 parent 8f7a714 commit c1c5103

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

two-sum/jiunshinn.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)