Created
September 19, 2018 11:16
-
-
Save aadimator/6e04fb00da66ac523cb07742001a8704 to your computer and use it in GitHub Desktop.
1. Two Sums - LeetCode
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
class Solution: | |
def twoSum(self, nums, target): | |
""" | |
:type nums: List[int] | |
:type target: int | |
:rtype: List[int] | |
""" | |
dict = {} | |
for i in range(len(nums)): | |
complement = target - nums[i] | |
if complement in dict: | |
return dict[complement], i | |
dict[nums[i]] = i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment