/* The guess API is defined in the parent class GuessGame. @param num, your guess @return -1 if my number is lower, 1 if my number is higher, otherwise return 0 int guess(int num); */publicclassSolutionextendsGuessGame { /** * @param n an integer * @return the number you guess */publicintguessNumber(int n) {finalint CORRECT =0, GUESS_SMALLER =-1, GUESS_LARGER =1;int left =1, right = n;while (left +1< right) {int mid = left + (right - left) /2;if (guess(mid)== CORRECT) {return mid; } elseif (guess(mid)== GUESS_SMALLER) { right = mid; } else { // (guess(mid) == GUESS_LARGER) left = mid; } }if (guess(left)== CORRECT) return left;if (guess(right)== CORRECT) return right;return0; }}