Skip to content

Commit ed7e3aa

Browse files
committed
Solve two-sum
1 parent 53ce7c7 commit ed7e3aa

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

two-sum/hypoxisaurea.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
class Solution:
4+
def twoSum(self, nums: List[int], target: int) -> List[int]:
5+
lookup = {}
6+
7+
for i, num in enumerate(nums):
8+
diff = target - num
9+
10+
if diff in lookup:
11+
return [lookup[diff], i]
12+
13+
lookup[num] = i
14+
15+
raise ValueError('No answer')

0 commit comments

Comments
 (0)