ALG-M020MediumTwo Pointers
Unique Zero-Sum Trios
Find all unique value triplets [a,b,c] from distinct positions that sum to zero. Sort numbers inside each triplet ascending, then return triplets in lexicographic order without duplicates.
Contract
input numbers: integer[]
return integer[][]
Constraints
- • 0 <= length <= 200
Examples
Example 1
numbers = [-1, 0, 1, 2, -1, -4]
→ [[-1, -1, 2], [-1, 0, 1]]
Example 2
numbers = [0, 0, 0, 0]
→ [[0, 0, 0]]
5 judge tests (2 shown above). Target complexity: O(n^2).