mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-26 10:24:30 +01:00
Co-authored-by: Merwane Hamadi <merwanehamadi@gmail.com> Co-authored-by: symphony <john.tian31@gmail.com>
20 lines
421 B
Python
20 lines
421 B
Python
# mypy: ignore-errors
|
|
from typing import List, Optional
|
|
|
|
|
|
def two_sum(nums: List, target: int) -> Optional[int]:
|
|
seen = {}
|
|
for i, num in enumerate(nums):
|
|
complement = target - num
|
|
if complement in seen:
|
|
return [seen[complement], i]
|
|
seen[num] = i
|
|
return None
|
|
|
|
|
|
# Example usage:
|
|
nums = [2, 7, 11, 15]
|
|
target = 9
|
|
result = two_sum(nums, target)
|
|
print(result) # Output: [0, 1]
|