Created
April 1, 2019 20:40
-
-
Save philippeback/9e383d5ecb5572a82a9fb337e9cb251c to your computer and use it in GitHub Desktop.
This file contains 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
class Solution: | |
def wanted(this, number, target): | |
return target - number | |
def twoSum(self, nums: List[int], target: int) -> List[int]: | |
wanted_dict = {} | |
for i in range(0, len(nums)): | |
num = nums[i] | |
entry = (i, self.wanted(num,target)) | |
wanted_dict[num]=entry | |
for i in range(0, len(nums)): | |
target_making_key = target - nums[i] | |
if target_making_key in wanted_dict: | |
(j, _) = wanted_dict[target_making_key] | |
if (i != j): | |
return (i,j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment