ASAPUtils Logo ASAPUtils
Week 1

3Sum

3Sum solved by sorting, fixing one element, and two-pointering the rest, with C++ and JavaScript solutions, a visualizer, and the duplicate-skipping that decides whether your submission passes.

medium Arrays Two Pointers O(n²) time · O(1) space Open on LeetCode ↗

The problem

Given an integer array, return all unique triplets that sum to zero. The triplets may be returned in any order, but the result must not contain duplicate triplets.

nums = [-1, 0, 1, 2, -1, -4] -> [[-1, -1, 2], [-1, 0, 1]]

Related Problems