3Sum
MediumTwo Pointers
Decode it first. Clues, constraints, pattern and plan before any code.Given a list of integers nums, return every unique triplet [a, b, c] of values taken from three different positions where a + b + c == 0. Two triplets with the same values count as the same triplet, so do not repeat them. The order of the triplets, and of the values inside each one, does not matter.
nums = [-1, 0, 1, 2, -1, -4] → [[-1, -1, 2], [-1, 0, 1]]
nums = [0, 1, 1] → []
nums = [0, 0, 0, 0] → [[0, 0, 0]]Constraints
3 <= nums.length <= 3000-10^5 <= nums[i] <= 10^5