Skip to content

Commit 3d46c71

Browse files
authored
Add error handling for no two sum solution
Raise ValueError if no two sum solution exists
1 parent 58d6d6f commit 3d46c71

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

data_structures/arrays/two_sum.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ def two_sum(array: list[int], target: int) -> list[int]:
5151
return [dictionary[array[i]], i]
5252

5353
dictionary[complement] = i
54+
55+
raise ValueError("No two sum solution exists")

0 commit comments

Comments
 (0)