Unique Triplets with Zero Sum

ARRAY

Problem

Given an array nums of integers, identify all the unique triplets [nums[i], nums[j], nums[k]] in the array which give a sum of zero.

Note that the solution set must not contain duplicate triplets, and each triplet should be returned as a list within the list of solutions. The order of the triplets in the final list does not matter.

Examples

findZeroSumTriplets([-2,0,1,1,2]); // returns 2 // Triplets: [ [-2, 0, 2], [-2, 1, 1] ] findZeroSumTriplets([-1,0,1,2,-1,-4,-3,-3,0,4]); // returns 5 [ [ -4, 0, 4 ], [ -3, -1, 4 ], [ -3, 1, 2 ], [ -1, -1, 2 ], [ -1, 0, 1 ] ]
Loading...