15. 3Sum

MediumTwo Pointers

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. The solution set must not contain duplicate triplets.

Examples

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

Output: [[-4,1,3],[-1,-1,2],[-1,0,1]]

Explanation: Public test case for 3Sum

Constraints

  • 3 <= nums.length <= 3000
  • -10^5 <= nums[i] <= 10^5
Loading...

Run checks all cases above. Submit evaluates all test cases.