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.
Return only unique triplets, with each triplet sorted in nondecreasing order and the result sorted lexicographically. The input array may be modified. Return an empty list when no valid triplet exists.
Function signature: def three_sum(nums):
Input is a list of integers. Output is a list of lists of three integers.
def three_sum(nums):