# 15ms java solution- beats 99% submissions

• I used a random number -111, you can set it to Integer.max_value or something
``` class Solution { public int threeSumClosest(int[] nums, int target) { int temp1=target,temp2=target; Arrays.sort(nums); int result=-111; while(result==-111){ int result1=find(nums, temp1--); int result2=find(nums, temp2++); if(result1==-111&&result2==-111) result=-111; else if(result1==-111) result=result2; else if(result2==-111) result=result1; else result= (Math.abs(target-result1)<Math.abs(target-result2)) ? result1 : result2; } return result; }```

``` public int find(int[] nums, int target) { int mainT=target; for(int i=0;i<nums.length-2;i++) { if(i==0 || ( i>0 && nums[i]!=nums[i-1] )){ target=mainT-nums[i]; int low=i+1,high=nums.length-1; while(low<high) { if(nums[low]+nums[high]==target) return target+nums[i]; else { if(nums[low]+nums[high]<target) low++; else high--; } } } } return -111; } ```

```} ```

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.