16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
给一个包含n个整数的数组S,从S中找3个整数使得它们的和最接近给定的另一个目标数字,返回这三个数字的和。你可以假设每一个输入有且只有一个解。
比如,给一个数组S = {-1, 2, 1, -4}, 和目标 1。
这个和最接近目标的是2. (-1 + 2 + 1 = 2).
你需要完成以下函数:
int threeSumClosest(int* nums, int numsSize, int target) {
}
这道题的网址是:“https://leetcode.com/problems/3sum-closest/#/description"
|