Loading...
Loading...
Loading...
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
The solution set must not contain duplicate triplets.
Input: Array of integers nums.
Output: List of unique triplets summing to zero (any order).
Input: nums = [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]
Explanation: Distinct triplets summing to 0 are (-1, -1, 2) and (-1, 0, 1). Other combos either repeat or don't sum to 0.
Input: nums = [0, 1, 1]
Output: []
Explanation: No triplet sums to 0.
Input: nums = [0, 0, 0]
Output: [[0, 0, 0]]
Explanation: Single valid triplet.
nums. Fix index i, then two pointers l = i+1, r = n-1 scan for pairs summing to -nums[i]. Skip duplicates at all three levels. Time: O(n²), Space: O(1) extra.(i,j), look up -(nums[i]+nums[j]). Harder to dedupe; sort-based is cleaner.i past equal values; after a hit, advance l and r past equal values too.3 <= nums.length <= 3000 -10^5 <= nums[i] <= 10^5