public static int threeSumClosest(int[] num, int target) {
		if (num == null || num.length < 3) {
			return Integer.MIN_VALUE;
		}
		Arrays.sort(num);
		int result = num[0] + num[1] + num[2];
		for (int i = 0; i < num.length; i++) {
			while (i > 0 && num[i] == num[i - 1]) {
				i++;
			}
			
			int start = i+1;
			int end = num.length - 1;
			while (start < end) {
				int current_result = num[i] + num[start] + num[end];
				//update the result
				if (Math.abs(target - current_result) < Math.abs(target - result) ) {
					result = current_result;
				}
				if (result == target) {
					return result;
				}
				if (current_result < target) {
					start ++;
				} else {
					end --;
				}
			}
		}
		return result;
	}