Guest User

Untitled

a guest
Oct 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class Solution:
  2. def fourSum(self, nums, target):
  3. """
  4. :type nums: List[int]
  5. :type target: int
  6. :rtype: List[List[int]]
  7. """
  8. nums = sorted(nums)
  9. res = []
  10. for i in range(len(nums)-3):
  11. for j in range(i+1, len(nums)-2):
  12. t = target - nums[i]- nums[j]
  13. k,l = j+1, len(nums)-1
  14. while k<l:
  15. if nums[k]+nums[l]==t:
  16. if tuple([nums[i],nums[j],nums[k],nums[l]]) not in res:
  17. res += [tuple([nums[i],nums[j],nums[k],nums[l]])]
  18. k+=1
  19. elif nums[k]+nums[l]<t:
  20. k+=1
  21. else:
  22. l-=1
  23. return [list(c) for c in set(res)]
Add Comment
Please, Sign In to add comment