classSolution:defthreeSum(self, nums: List[int])-> List[List[int]]:
nums.sort()
res =[]
visited_numi =[]# 第一处去重for i inrange(len(nums)-2):if nums[i]notin visited_numi:
visited_numi.append(nums[i])
sortnums = nums[i+1:]
l, r =0,len(sortnums)-1while r > l:if sortnums[l]+ sortnums[r]==- nums[i]:
res.append([nums[i], sortnums[l], sortnums[r]])while l < r and sortnums[l +1]== sortnums[l]: l +=1# 第二处去重while l < r and sortnums[r -1]== sortnums[r]: r -=1
l +=1
r -=1elif sortnums[l]+ sortnums[r]>- nums[i]: r -=1else: l +=1return res