int threeSumClosest (int[] num, int target) {
		int n = num.length, closest = 0;
		boolean flag = false; //if or not closest has been initialized
		int min, mid, max, sum;
		Arrays.sort(num);
		int k = n-1, j = k-1, i;
		while (k > j) {
			i = 0;
			j = k-1;
			max = num[k];
			
			while (j > i && k > j) {
				min = num[i];
				mid = num[j];
				sum = max + mid + min;
				if (flag == false) {
					closest = sum - target;
					flag = true;
				} else {
					if (Math.pow(closest, 2) > Math.pow(sum-target, 2)) {
						closest = sum - target;
					}
				}
				
				if (closest == 0) {
					return target;
				} else if (sum - target < 0) {
					i++;
				} else if (sum - target > 0){
					j--;
				}
			}
			k--;
		}
		return closest+target;
	}