public int threeSumClosest(int[] num, int target) {
        if(num == null || num.length < 3) return 0;
        Arrays.sort(num);
        int res = num[0] + num[1] + num[2];
        for(int i = 0; i <= num.length - 3; i++) {
        	int j = i + 1, k = num.length - 1;
        	while(j < k) {
        		int sum = num[i] + num[j] + num[k];
        		if(Math.abs(sum - target) < Math.abs(res - target)) res = sum;
        		if(sum == target) return target;
        		else if(sum > target) k--;
        		else j++;
        	}
        }
        return res;
	}