Three Sum
Problem statement
Given an integer array nums, return every unique triplet of values whose sum is zero. Each triplet must use three different array positions.
Sort the values within each triplet in nondecreasing order. Return the triplets in lexicographic order: compare the first values, then the second, then the third. Different index choices with the same three values produce one result. Return an empty array if there is no valid triplet. You may reorder nums.
Function
threeSum(nums: int[]) → List<List<Integer>>Examples
Example 1
nums = [-1,0,1,2,-1,-4]return = [[-1,-1,2],[-1,0,1]]The unique value triplets are [-1,-1,2] and [-1,0,1]. Both sum to zero. Reusing the other occurrence of -1 with 0 and 1 does not create another value triplet.
Example 2
nums = [0,0,0,0]return = [[0,0,0]]Any choice of three positions gives [0,0,0]. Return this value triplet once.
Constraints
0 <= nums.length <= 100-100000 <= nums[i] <= 100000