In a card game, you hold n cards. The list nums gives the number written on each card, and a number can be negative. The game also gives you a goal number, target.
Pick exactly three different cards (three different positions in the list). Add up their numbers. Find the choice whose sum is nearest to target, and return that sum.
Every test has just one sum that is nearest, so you never have to break a tie.
Examples
Example 1:
Input: nums = [-3,0,2,7], target = 8
Output: 9
Explanation: The four possible sums are -1, 4, 6 and 9. The sum 9 is only 1 away from 8, which is the nearest.
Example 2:
Input: nums = [1,1,1,0], target = -50
Output: 2
Explanation: The goal is far below every sum. The smallest sum, 1 + 1 + 0 = 2, is the nearest to it.
Example 3:
Input: nums = [5,5,5], target = 15
Output: 15
Explanation: Only one choice of three cards exists, and its sum is exactly the goal.