Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def fourSum(self, nums, target):
- """
- :type nums: List[int]
- :type target: int
- :rtype: List[List[int]]
- """
- nums = sorted(nums)
- res = []
- for i in range(len(nums)-3):
- for j in range(i+1, len(nums)-2):
- t = target - nums[i]- nums[j]
- k,l = j+1, len(nums)-1
- while k<l:
- if nums[k]+nums[l]==t:
- if tuple([nums[i],nums[j],nums[k],nums[l]]) not in res:
- res += [tuple([nums[i],nums[j],nums[k],nums[l]])]
- k+=1
- elif nums[k]+nums[l]<t:
- k+=1
- else:
- l-=1
- return [list(c) for c in set(res)]
Add Comment
Please, Sign In to add comment