//一次AC 有点爽的
class Solution { public: int threeSumClosest(vector<int>& nums, int target) { int res = 0; int minal = INT_MAX; sort(nums.begin(),nums.end()); for(int i=0;i < nums.size()-2;i++){ int cnt = target-nums[i]; for(int j=i+1,k=nums.size()-1;j < k;){ int sum = nums[j]+nums[k]; if(sum < cnt){j++;} else if(sum > cnt){k--;} else{ res = target; return res; } if(minal > abs(sum-cnt)){minal = abs(sum-cnt);res = sum+nums[i];} } } return res; } };