public int threeSumClosest(int[] num, int target) {
    	int ret = 0;
    	boolean init = false;
    	
    	Arrays.sort(num);
    	for (int i = 0; i < num.length; i++)
    	{
    		int j = i + 1;
    		int k = num.length - 1;
    		while (j < k)
    		{
        		int delta = num[i] + num[j] + num[k] - target;
        		int dist = Math.abs(delta);
        		if (dist < Math.abs(ret - target) || init == false)
        		{
        			init = true;
        			ret = num[i] + num[j] + num[k];
        		}

        		if (delta < 0)
        			j++;
        		else
        			k--;
    		}
    	}
    	return ret; 
    }