rosien

two_sum

Oct 14th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. #https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
  2. def twoSum(self, numbers, target):
  3.        
  4.     c = collections.defaultdict(int)
  5.     for i, n in enumerate(numbers):
  6.         if n in c:
  7.            return [c[n], i+1]
  8.          diff = target - n
  9.          c[diff] = i+1
  10.            
Add Comment
Please, Sign In to add comment