Skip to content

Instantly share code, notes, and snippets.

@aadimator
Created September 19, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadimator/6e04fb00da66ac523cb07742001a8704 to your computer and use it in GitHub Desktop.
Save aadimator/6e04fb00da66ac523cb07742001a8704 to your computer and use it in GitHub Desktop.
1. Two Sums - LeetCode
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