medium

3Sum

Given an integer array, return all unique triplets of elements whose sum is zero. The same triplet must not appear twice in the output, though the array may contain duplicates.

Constraints
  • 3 ≤ n ≤ 3000
  • -10^5 ≤ nums[i] ≤ 10^5
Examples
in: nums = [-1, 0, 1, 2, -1, -4]
out: [[-1,-1,2],[-1,0,1]]

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.