← 返回 meta 的题目列表3Sum Problem
类型:online_judge
You are given an integer array. Find all unique triplets (a, b, c) in the array such that their sum is zero, without using extra space. The input array can include positives, negatives, and zeros. The algorithm should aim for a time complexity of O(n^2) if the array length does not exceed 3000. Example:
Input: [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]
Note that the order of the output and the triplet order does not matter.
Example
Input
[-1, 0, 1, 2, -1, -4]