3Sum
Given an integer array nums, return all unique triplets [nums[i], nums[j], nums[k]] such that:
i,j, andkare distinct indices.nums[i] + nums[j] + nums[k] == 0.
The solution set must not contain duplicate triplets. You may return the triplets in any order.
Example 1
Input
nums = [-1,0,1,2,-1,-4]Output
[[-1,-1,2],[-1,0,1]]The triplets [-1, -1, 2] and [-1, 0, 1] are the unique combinations that sum to 0.
Example 2
Input
nums = [0,1,1]Output
[]No three distinct elements in the array sum to 0.
Constraints
- 3 <= nums.length <= 3000
- -10^5 <= nums[i] <= 10^5