intthreeSumClosest(vector<int>& nums, int target){ sort(nums.begin(),nums.end()); int size = nums.size(); int res = nums[0] + nums[1] + nums[2]; for (int i = 0; i < size - 2; i++) { int j = i + 1; int k = size - 1; while (j < k) { int sum = nums[i] + nums[j] + nums[k]; if (abs(sum-target) < abs(res-target)) res = sum; if (sum < target) ++j; elseif (sum > target) --k; else return target; } } return res; }