← Practice · Two pointers

3Sum Medium

Given an integer array nums, return all unique triplets [a,b,c] such that a + b + c = 0. The result must not contain duplicate triplets; order does not matter.

Examples

  • [-1,0,1,2,-1,-4] -> [[-1,-1,2],[-1,0,1]]
  • [0,0,0] -> [[0,0,0]]

Define a function named threeSum in JavaScript.

00:00

JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests