Created
February 2, 2020 14:53
-
-
Save ak9999/1a3b594a05411d008a9254e9af977a60 to your computer and use it in GitHub Desktop.
Return two numbers that add up to a target sum.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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