def threesum_zero(A):
    """Given an array of unsorted numbers, find all unique triplets that
    sum up to zero.

    [LC-0015]

    >>> threesum_zero([-3, 0, 1, 2, -1, 1, -2])
    [[-3, 1, 2], [-2, 0, 2], [-2, 1, 1], [-1, 0, 1]]

    >>> threesum_zero([-5, 2, -1, -2, 3])
    [[-5, 2, 3], [-2, -1, 3]]

    >>> threesum_zero([-1, 0, 1, 2, -1, -4])
    [[-1, -1, 2], [-1, 0, 1]]

    >>> threesum_zero([])
    []

    >>> threesum_zero([0])
    []

    """
    A = sorted(A)
    results = []
    for left in range(len(A) - 2):
        if left > 0 and A[left - 1] == A[left]:
            continue
        mid, right = left + 1, len(A) - 1
        while mid < right:
            s = A[left] + A[mid] + A[right]
            if s < 0:
                mid += 1
            elif s > 0:
                right -= 1
            else:
                results.append([A[left], A[mid], A[right]])
                mid += 1
                right -= 1
    return results