public int threeSumClosest(int[] num, int target) {
        if (num == null || num.length < 3) return Integer.MAX_VALUE;
        Arrays.sort(num);
        int minDiff = Integer.MAX_VALUE;
        for(int i = 0; i < num.length - 2; i++) {
            int left = i + 1, right = num.length - 1;
            while(left < right) {
                int diff = num[i] + num[left] + num[right] - target;
                if(Math.abs(diff) < Math.abs(minDiff)) {
                    minDiff = diff;
                }
                if(diff == 0) {
                    return target;
                } else if(diff < 0) {
                    ++left;
                } else {
                    --right;
                }
            }
        }
        return target + minDiff;
    }