3Sum
Given an integer array nums, return all triplets [nums[i], nums[j], nums[k]] such that i, j and k are different indices and
nums[i] + nums[j] + nums[k] === 0
The answer must not contain duplicate triplets: two triplets with the same three values count as one, whatever positions they came from. You may return the triplets in any order, and the numbers inside each triplet in any order.
Constraints
3 <= nums.length <= 3000-10^5 <= nums[i] <= 10^5
Examples
Example 1
Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]]
Two different triplets sum to 0. [-1, 0, 1] can be made with either -1, but it is listed once. The order of triplets, and of numbers inside a triplet, doesn't matter.
Example 2
Input: nums = [0,1,1] Output: []
The only triplet sums to 2.
Example 3
Input: nums = [0,0,0] Output: [[0,0,0]]
JavaScript you'll use: Sorting and comparators Arrays: create, read, update
/**
* @param {number[]} nums
* @return {number[][]}
*/
function threeSum(nums) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.