intthreeSumClosest(vector<int>& nums, int target){ int n = nums.size(); if (n < 3) throw"the size of nums must bigger than 3"; sort(nums.begin(), nums.end()); int diff = 32765; int res; int now = 0; while(now < n-2){ int low = now + 1; int high = n - 1; while(low < high){ int tempSum = nums[now] + nums[low] + nums[high]; int tempDiff = tempSum - target; if(abs(tempDiff) < diff){ diff = abs(tempDiff); res = tempSum; } if(tempDiff == 0){ return res; }elseif(tempDiff > 0){ changePosSub(high, nums); }else{ changePosAdd(low, nums, n); } }