3Sum
Medium
LC #15
sortingk-sumduplicatesNot attempted yet
Return all unique triplets [a, b, c] of values from
nums, taken from three different positions, such that
a + b + c == 0.
No triplet may appear twice (as a multiset of values). You can return the triplets, and the numbers inside each triplet, in any order.
Example 1
Input: nums = [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]
Example 2
Input: nums = [0, 1, 1]
Output: []
Example 3
Input: nums = [0, 0, 0]
Output: [[0, 0, 0]]
Constraints
- 3 ≤ len(nums) ≤ 3000
- -10⁵ ≤ nums[i] ≤ 10⁵