cheetcode

12. 3SumMedium

Return every unique triplet whose values sum to zero.

Given an integer array nums, return all the unique triplets [nums[i], nums[j], nums[k]] such that i, j, and k are distinct and nums[i] + nums[j] + nums[k] == 0.

The solution set must not contain duplicate triplets.

You may return the answer in any order.

Examples

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Input: nums = [0,1,1]
Output: []

Constraints

  • 3 <= nums.length <= 3,000
  • -100,000 <= nums[i] <= 100,000