Design an efficient algorithm to find all unique triplets in an array that sum up to zero.
Implement three_sum(nums) to return every triplet as an ascending list, with no duplicate triplets; the overall result may be returned in any order. For example, [-1, 0, 1, 2, -1, -4] returns [[-1, -1, 2], [-1, 0, 1]], while [0, 0, 0, 0] returns [[0, 0, 0]].
def three_sum(nums):