Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions interview-bootcamp/Two-Sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def two_sum(nums: list[int], target: int) -> tuple[int, int] | None:

Check failure on line 1 in interview-bootcamp/Two-Sum.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (INP001)

interview-bootcamp/Two-Sum.py:1:1: INP001 File `interview-bootcamp/Two-Sum.py` is part of an implicit namespace package. Add an `__init__.py`.
"""
Find two numbers in the list 'nums' that add up to 'target'.

:param nums: List of integers
:param target: Integer target sum
:return: Tuple of the two numbers that add up to target, or None if no such pair exists

Check failure on line 7 in interview-bootcamp/Two-Sum.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

interview-bootcamp/Two-Sum.py:7:89: E501 Line too long (91 > 88)
"""
num_set = set()

for num in nums:
complement = target - num
if complement in num_set:
return (complement, num)
num_set.add(num)

return None


if __name__ == "__main__":
print(two_sum([2, 7, 11, 15], 9))
Loading