class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
ans = []
nums.sort()
for first in range(len(nums) - 2):
if first > 0 and nums[first] == nums[first - 1]: # 第一个指针, 只考虑重复数字中的第一个
continue
third = len(nums) - 1
target = -nums[first]
for second in range(first + 1, len(nums) - 1):
if second > first + 1 and nums[second] == nums[second - 1]: # 第二个指针, 只考虑第一个指针后, 重复数字中的第一个
continue
second_num = nums[second]
while third > second and second_num + nums[third] > target:
third -= 1
if third <= second:
break
if second_num + nums[third] == target:
ans.append([nums[first], second_num, nums[third]])
return ans