This question evaluates array-based algorithm design, handling of duplicate results, and analysis of time and space complexity when producing unique triplets that sum to zero.
Given an integer array nums, return all unique triplets [nums[i], nums[j], nums[k]] such that:
i
,
j
, and
k
are
distinct indices
(
i != j != k
), and
nums[i] + nums[j] + nums[k] == 0
.
The returned triplets must be unique (i.e., no duplicate triplets in the output). Triplets can be returned in any order.
nums
: an array of integers
0 <= nums.length <= 3000
-10^5 <= nums[i] <= 10^5
nums = [-1, 0, 1, 2, -1, -4]
[[-1, -1, 2], [-1, 0, 1]]