3Sum
Problem statement
Given an integer array nums, return every unique triplet [a, b, c] whose values sum to 0.
Each returned triplet must be sorted in ascending order. Return the complete list of triplets in lexicographic order, without duplicates.
Function
threeSum(nums: int[]) → int[][]Examples
Example 1
nums = [-1,0,1,2,-1,-4]return = [[-1,-1,2],[-1,0,1]]The two unique value triplets that sum to 0 are [-1,-1,2] and [-1,0,1].
Example 2
nums = [0,0,0,0]return = [[0,0,0]]All valid index choices produce the same value triplet, so [0,0,0] appears only once.
Constraints
3 <= nums.length <= 3000.-100000 <= nums[i] <= 100000.