Implement the 3-Sum problem.
Given an integer array nums, return every unique triplet [a, b, c] such that a + b + c == 0. Each input element may be used at most once. The result must not contain duplicate triplets, and each triplet must be in nondecreasing order. Return the triplets in lexicographic order after sorting the input values.
Function signature: three_sum(nums)
Input is a list of integers. Output is a list of triplets.
def three_sum(nums):