classSolution:deffourSum(self,nums: List[int],target:int) -> List[List[int]]: n =len(nums)if n <4:return [] nums.sort() res = []for i inrange(n -3):if i >0and nums[i]== nums[i -1]:continuefor j inrange(i +1, n -2):if j > i +1and nums[j]== nums[j -1]:continue diff = target - nums[i]- nums[j] left, right = j +1, n -1while left < right: t = nums[left]+ nums[right]if t == diff: res.append([nums[i], nums[j], nums[left], nums[right]])while left < right and nums[right]== nums[right -1]: right -=1while left < right and nums[left]== nums[left +1]: left +=1 right -=1 left +=1elif t > diff: right -=1else: left +=1return res