Choose three different positions of nums and return the sum that is closest to target. If two sums are equally close, return the smaller one.
For nums = [-1, 2, 1, -4] and target = 1 the answer is 2 (-1 + 2 + 1).
The starter code tries every triple. It is correct but too slow for long lists.
Example 1
Input:
three_sum_closest([-1, 2, 1, -4], 1)
Output:
2
Example 2
Input:
three_sum_closest([0, 0, 0], 1)
Output:
0
3 <= len(nums) <= 1000-1000 <= nums[i] <= 1000-3000 <= target <= 3000No results yet
Run your code to check it against the examples, or submit to run every test.