@@ -0,0 +1,947 @@
+/*%0A * Leetcode 16: 3Sum Closest%0A * https://leetcode.com/problems/3sum-closest/%0A * Martin.Xia%0A */%0A%0Apublic class Solution %7B%0A    public int threeSumClosest(int%5B%5D num, int target) %7B%0A        int closest = num%5B0%5D + num%5B1%5D + num%5B2%5D;%0A        int diff = Math.abs(closest - target);%0A        Arrays.sort(num);%0A        for (int i = 0; i %3C num.length - 2; i++) %7B%0A            int start = i + 1;%0A            int end = num.length - 1;%0A            while (start %3C end) %7B%0A                int sum = num%5Bi%5D + num%5Bstart%5D + num%5Bend%5D;%0A                int newDiff = Math.abs(sum - target);%0A                if (newDiff == 0) %7B%0A                    return target;%0A                %7D%0A                if (newDiff %3C diff) %7B%0A                    diff = newDiff;%0A                    closest = sum;%0A                %7D%0A                if (sum %3C target)%0A                    start++;%0A                else%0A                    end--;%0A            %7D%0A        %7D%0A        return closest;%0A    %7D%0A%7D

Leetcode 16: 3Sum Closest