← All problems
3Sum
Given an integer array nums, return all unique triplets [a, b, c] such that a + b + c = 0. The solution set must not contain duplicate triplets, and triplets may be returned in any order. Aim for better than the naive O(n^3) enumeration.
Complexity
Time O(n^2), Space O(1) excluding output
Common pitfalls
- Duplicate triplets from not skipping
- O(n^3) brute force timing out
Your solution
Log in to save your code and track progress.