Advertisement
Guest User

1. Two Sum

a guest
Feb 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  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]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement