Problem intuition
- The brute-force approach checks every triple and deduplicates with a set.
- The better route sorts first, fixes one number, and then solves the remaining pair with two pointers while skipping duplicates.
Return every unique triplet whose values sum to zero without repeating duplicate triplets.
Two PointersThe solutions below are ordered from least optimal to most optimal, so you can see the improvement path instead of only the final answer.
Solution 1
Solution 2