Skip to content

Instantly share code, notes, and snippets.

@ak9999
Created February 2, 2020 14:53
Show Gist options
  • Save ak9999/1a3b594a05411d008a9254e9af977a60 to your computer and use it in GitHub Desktop.
Save ak9999/1a3b594a05411d008a9254e9af977a60 to your computer and use it in GitHub Desktop.
Return two numbers that add up to a target sum.
from typing import List
def twoSum(nums: List[int], target: int) -> List[int]:
answers = []
for n in nums:
answers.append(target - n)
ans = set(answers) & set(nums)
return ans
if __name__ == "__main__":
import sys
from random import randint
# array = [randint(1,11) for i in range(10)]
array = [2, 7, 11, 15]
print(
twoSum(nums=array, target=int(sys.argv[1]))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment