@@ -0,0 +1,1141 @@
+/***%0A * Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.%0A *%0A *     For example, given array S = %7B-1 2 1 -4%7D, and target = 1.%0A *%0A *     The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).%0A */%0Aimport java.util.ArrayList;%0A%0Apublic class Solution %7B%0A    public int threeSumClosest(int%5B%5D num, int target) %7B%0A        int n = num.length;%0A        Arrays.sort(num);%0A        int ret = 0;%0A        int mingap = Integer.MAX_VALUE;%0A        int i, j, k;%0A        int sum, gap;%0A        for (i = 0; i %3C n - 2; i++) %7B%0A            j = i + 1;%0A            k = n - 1;%0A            while (j %3C k) %7B%0A                sum = num%5Bi%5D + num%5Bj%5D + num%5Bk%5D;%0A                gap = Math.abs(sum - target);%0A                if (gap %3C mingap) %7B%0A                    ret = sum;%0A                    mingap = gap;%0A                %7D%0A%0A                if (sum %3E target) %7B%0A                    k--;%0A                %7D else %7B%0A                    j++;%0A                %7D%0A            %7D%0A        %7D%0A        return ret;%0A    %7D%0A%7D%0A

add 3SumClosest.java