Two PointersMedium

3Sum

Return every different group of three numbers from nums (at three different positions) that adds up to 0. Groups can be in any order, and so can the numbers inside a group, but no group may repeat.

Example 1nums = [-2, 0, 1, 1, 2, -3] → [[-2, 0, 2], [-2, 1, 1], [-3, 1, 2]]
Example 2nums = [0, 0, 0, 0] → [[0, 0, 0]]
3 ≤ n ≤ 3000 · −10⁵ ≤ nums[i] ≤ 10⁵

Hints

0 of 3 open
Hint 2 · the patternHint 3 · the key line