SHARE
TWEET

Untitled

a guest Jun 18th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (arr.length < 3)
  2.             return -1;
  3.         int minDiff = Math.abs(arr[0] + arr[1] + arr[2] - target);
  4.         int bestTillNow = arr[0] + arr[1] + arr[2];
  5.         for (int i = 0; i < arr.length; i++) {
  6.             for (int j = i + 1; j < arr.length; j++) {
  7.                 for (int k = j + 1; k < arr.length; k++) {
  8.                     int newDiff = Math.abs(arr[i] + arr[j] + arr[k] - target);
  9.                     if (newDiff < minDiff) {
  10.                         minDiff = newDiff;
  11.                         bestTillNow = arr[i] + arr[j] + arr[k];
  12.                     }
  13.                 }
  14.             }
  15.         }
  16.         return bestTillNow;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top