input: Write a python function to find all unique triplets in the list which gives the sum of the target.
  assert three_sum([1, 2, 3, 4, 5, 6], 10) == [[1, 3, 6], [2, 3, 5], [1, 4, 5]]
  assert three_sum([1, 3, 5, 7, 10, 2, 4, 8], 15) == [[1, 7, 7], [3, 5, 7], [3, 7, 5], [5, 7, 3], [5, 10, 0], [7, 10, -2], [10, 2, 3], [2, 4, 9], [4, 8, 3]]
  assert three_sum([-1, 0, 1, 2, -1, -4], 0) == [[-1, 0, 1], [-1, -1, 2]]
output: def three_sum(nums, target):
      nums.sort()
      result = []
      for i in range(len(nums)-2):
          if i > 0 and nums[i] == nums[i-1]:
              continue
          l, r = i+1, len(nums)-1
          while l < r:
              s = nums[i] + nums[l] + nums[r]
              if s == target:
                  result.append([nums[i], nums[l], nums[r]])
                  while l < r and nums[l] == nums[l+1]:
                      l += 1
                  while l < r and nums[r] == nums[r-1]:
                      r -= 1
                  l += 1
                  r -= 1
              elif s < target:
                  l += 1
              else:
                  r -= 1
      return result