Back to DSA
3Sum
mediumFrom a given integer array, find every unique triplet of elements that sums to zero. No two triplets in the result should contain the same multiset of values. Return all such triplets.
Examples
Example 1:
Input:
nums = [-3,-1,0,1,2,4]Output:
[[-3,-1,4],[-3,1,2]]Explanation: Two distinct triplets sum to zero: (-3)+(-1)+4 = 0 and (-3)+1+2 = 0.
Example 2:
Input:
nums = [0,0,0,0]Output:
[[0,0,0]]Explanation: The only triplet that sums to zero consists of three zeroes.
Hints
1234567