Skip to content

Commit a075bfc

Browse files
committed
Two-Sum 01
1 parent d48e8a3 commit a075bfc

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

interview-bootcamp/Two-Sum.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
def to_sum(nums, target):
1+
def two_sum(nums: list[int], target: int) -> tuple[int, int] | None:
22
"""
3-
This function finds two numbers in the list 'nums' that add up to 'target'.
4-
3+
Find two numbers in the list 'nums' that add up to 'target'.
4+
55
:param nums: List of integers
66
:param target: Integer target sum
77
:return: Tuple of the two numbers that add up to target, or None if no such pair exists
88
"""
99
num_set = set()
10-
10+
1111
for num in nums:
1212
complement = target - num
1313
if complement in num_set:
1414
return (complement, num)
1515
num_set.add(num)
16-
16+
1717
return None
1818

19+
1920
if __name__ == "__main__":
20-
print(to_sum([2, 7, 11, 15], 9))
21+
print(two_sum([2, 7, 11, 15], 9))

0 commit comments

Comments
 (0)