@@ -0,0 +1,1474 @@
+/**%0A * Given an array S of n integers, %0A * find three integers in S such that the sum is closest to a given number, target. %0A * Return the sum of the three integers. You may assume that each input would have exactly one solution.%0A */%0Apublic class Solution %7B%0A    public int threeSumClosest(int%5B%5D nums, int target) %7B%0A        // Sort the array to make it run in O(N%5E2) time.%0A        Arrays.sort(nums);%0A%0A        // No index out of bounds error due to a guaranteed sum.%0A        int closestSum = nums%5B0%5D + nums%5B1%5D + nums%5B2%5D;%0A%0A        for (int i = 0; i %3C nums.length; i ++) %7B%0A            int currentTarget = target - nums%5Bi%5D;%0A            int j = i + 1;%0A            int k = nums.length - 1;%0A%0A            // Find the target relative to index i.%0A            while (j %3C k) %7B%0A                int currentSum = nums%5Bj%5D + nums%5Bk%5D;%0A%0A                // If the sum is actually found, then just return this as it is as close as can be.%0A                if (currentSum == currentTarget) return target;%0A%0A                // Update the closest sum to whichever is closer.%0A                int prevDiff = Math.abs(closestSum - target);%0A                int currDiff = Math.abs(currentSum + nums%5Bi%5D - target);%0A                closestSum = prevDiff %3E currDiff ? currentSum + nums%5Bi%5D : closestSum;%0A                if (currentSum %3E currentTarget) %7B%0A                    k --;%0A                %7D else %7B%0A                    j ++;%0A                %7D%0A%0A            %7D%0A        %7D%0A%0A        return closestSum;%0A    %7D%0A%7D%0A

Add 3sum closest #16