public static int threeSumClosest(int[] num, int target) {
		if (num.length < 3) {
			return Integer.MIN_VALUE;
		}

		int closest = Integer.MAX_VALUE;
		Arrays.sort(num);
		for (int i = 0; i < num.length; i++) {
			if (i > 0 && num[i] == num[i - 1]) {
				continue;
			}
			int x = num[i];
			int k = i + 1;
			int j = num.length - 1;
			while (k < j) {
				int sum = x + num[k] + num[j];
				if (sum == target) {
					closest = target;
					return target;
				} else if (sum > target) {
					j--;
				} else {
					k++;
				}
				int diff = sum - target;
				if (closest == Integer.MAX_VALUE
						|| Math.abs(diff) < Math.abs(closest - target)) {
					closest = sum;
				}
			}
		}
		return closest;
	}