@@ -0,0 +1,1053 @@
+package problems;%0A%0Aimport java.util.Arrays;%0A%0Apublic class Sum3Closest %7B%0A    public int threeSumClosest(int%5B%5D num, int target) %7B%0A        if (num.length %3C 3)%0A            return 0;%0A%0A        Arrays.sort(num);%0A%0A        int closest = num%5B0%5D + num%5B1%5D + num%5B2%5D;%0A        for (int i = 0; i %3C num.length - 2; i++) %7B%0A            if (i %3E 0 && num%5Bi%5D == num%5Bi - 1%5D)%0A                continue;%0A%0A            int p = i + 1, q = num.length - 1;%0A            while (p %3C q) %7B%0A                int t = num%5Bp%5D + num%5Bq%5D + num%5Bi%5D;%0A                if (t == target)%0A                    return t;%0A                if (Math.abs(t - target) %3C Math.abs(closest - target))%0A                    closest = t;%0A                if (t %3C target)%0A                    p++;%0A                else%0A                    q--;%0A            %7D%0A        %7D%0A        return closest;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Sum3Closest sc = new Sum3Closest();%0A        int%5B%5D num = %7B 1, 3, 4, 8, 3, 5 %7D;%0A        int target = 9;%0A        System.out.println(sc.threeSumClosest(num, target));%0A    %7D%0A%7D%0A

Add 3 Sum Closest