text: from typing import List
  
  
  class Solution:
      def threeSum(self, nums: List[int]) -> List[List[int]]:
          length = len(nums)
  
          if length < 3:
              return []
  
          nums.sort()
  
          triplets = set()
  
          for i in range(length):
              target = -nums[i]
  
              left_pointer = i + 1
              right_pointer = length - 1
  
              while left_pointer < right_pointer:
                  left = nums[left_pointer]
                  right = nums[right_pointer]
  
                  sum_at_pointers = left + right
  
                  if sum_at_pointers < target:
                      left_pointer += 1
  
                  elif sum_at_pointers > target:
                      right_pointer -= 1
  
                  else:
                      triplet = tuple(sorted([-target, left, right]))
                      triplets.add(triplet)
  
                      left_pointer += 1
                      right_pointer -= 1
  
          return list(list(triplet) for triplet in triplets)
  
  
  def test():
      solution = Solution()
      assert solution.threeSum([]) == []
      assert solution.threeSum([0]) == []
      assert solution.threeSum([-1, 1]) == []
      assert solution.threeSum([-1, 0, 1]) == [[-1, 0, 1]]
  
      triplets = solution.threeSum([-1, 0, 1, 2, -1, -4])
      assert triplets == [[-1, 0, 1], [-1, -1, 2]]
      assert solution.threeSum([-10 ** 5] * 1500 + [10 ** 5] * 1499 + [0])
  