Skip to content
Problem · Canonical Warm-Up
mediumsort · two-pointer · duplicate-skipTime · O(n^2)Space · O(1)

3Sum Triplet Target

Problem walkthrough: statement, hints, solution, mistakes

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, j != k, and nums[i] + nums[j] + nums[k] == 0.

The solution set must not contain duplicate triplets.

Constraints

  • 3 ≤ nums.length ≤ 3000
  • -105 ≤ nums[i] ≤ 105

Examples

Input:  [-1,0,1,2,-1,-4]  -> [[-1,-1,2],[-1,0,1]]
Input:  [0,1,1]            -> []
Input:  [0,0,0]            -> [[0,0,0]]