与上一道题及其相似 也没什么好办法
public int threeSumClosest1(int[] nums, int target) { Arrays.sort(nums); int len = nums.length; int sum = 0; int max = Integer.MAX_VALUE; for (int first = 0; first < len; first++) { int second = first + 1, third = nums.length - 1; while (third>second){ if (nums[first]+nums[second]+nums[third]==target){ return target; } if (Math.abs((nums[first]+nums[second]+nums[third]-target))<max){ sum = nums[first]+nums[second]+nums[third]; max =Math.abs(sum-target); } if(nums[first]+nums[second]+nums[third]>target){ third --; }else{ second++; } } } return sum; }