3Sum
Problem statement
Given an integer array nums, return every unique triplet of values [a, b, c] whose elements come from three distinct indices and sum to 0.
Output Rules
- Sort each triplet in ascending order.
- Sort the list of triplets lexicographically.
- Do not return duplicate triplets.
Function
threeSum(nums: int[]) → List<List<Integer>>Examples
Example 1
nums = [-1,0,1,2,-1,-4]return = [[-1,-1,2],[-1,0,1]]Example 2
nums = [0,0,0,0]return = [[0,0,0]]The same value triplet is returned only once.
Constraints
3 <= nums.length <= 3000.-10^5 <= nums[i] <= 10^5.