Guest User

twoSum = py

a guest
Jun 18th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. class Solution:
  2.  
  3. def __init__(self):
  4. self.flag = True
  5.  
  6. def two_sum(self, nums: List[int], target: int) -> List[int]:
  7. result = []
  8. ndx = {}
  9. for i in range(len(nums)):
  10. x = target - nums[i]
  11. n = ndx.get(x)
  12. if n != None:
  13. result = [n, i]
  14. break
  15. ndx[nums[i]] = i
  16. return result
Advertisement
Add Comment
Please, Sign In to add comment