3Sum

Problem Given an integer array, return all unique triplets [a, b, c] with a + b + c = 0. The solution set must not contain duplicate triplets.

Input / Output

  • Input: int array nums.
  • Output: list of unique zero-sum triplets.

Constraints

  • 3 <= n <= 3000; O(n^2) expected — the O(n^3) brute force is the warm-up only.

Example

  • nums = [-1,0,1,2,-1,-4] -> [[-1,-1,2],[-1,0,1]]
asked …
LeaderboardSalaryAccount