classSolution:deffourSum(self,nums: List[int],target:int) -> List[List[int]]: res = [] nums.sort() i =0while i <len(nums): j = i+1while j <len(nums): front, back = j+1,len(nums)-1while front < back: tmp_sum = nums[i]+ nums[j]+ nums[front]+ nums[back]if tmp_sum < target: front +=1elif tmp_sum > target: back -=1else:#四元组 quad = [nums[i], nums[j], nums[front], nums[back]] res.append(quad)while front < back and nums[front]== quad[2]: front +=1while front < back and nums[back]== quad[3]: back -=1while j+1<len(nums)and nums[j+1]== nums[j]: j +=1 j +=1#结束j循环while i+1<len(nums)and nums[i+1]== nums[i]: i +=1 i +=1#结束i循环return res