SHARE
TWEET

1. Two Sum

a guest Feb 18th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution(object):
  2.     def twoSum(self, nums, target):
  3.         dic = dict()
  4.         i = 0
  5.         for num in nums:
  6.             complement = target - num
  7.             if complement in dic:
  8.                 return [dic[complement], i]
  9.             else:
  10.                 dic[num] = i
  11.             i += 1
  12.  
  13.         return [-1, -1]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top