30. Zero-Sum Triplets
mediumarraytwo pointerssorting
Return every unique triplet [a, b, c] of values from nums (using distinct indices) such that a + b + c = 0.
Sort the numbers inside each triplet ascending, and sort the list of triplets lexicographically.
Example 1
Inputnums = [-1,0,1,2,-1,-4]
Output[[-1,-1,2],[-1,0,1]]
Example 2
Inputnums = [0,1,1]
Output[]
Example 3
Inputnums = [0,0,0]
Output[[0,0,0]]
Constraints
- 3 ≤ nums.length ≤ 3000
- -10⁵ ≤ nums[i] ≤ 10⁵