1 /* The guess API is defined in the parent class GuessGame. 2 @param num, your guess 3 @return -1 if my number is lower, 1 if my number is higher, otherwise return 0 4 int guess(int num); */ 5 6 public class Solution extends GuessGame { 7 public int guessNumber(int n) { 8 int start = 1, end = n; 9 while (start < end) {10 int mid = start + (end - start)/2;11 if (guess(mid) == 0) {12 return mid;13 } else if (guess(mid) == 1) {14 start = mid + 1;15 } else {16 end = mid - 1;17 }18 }19 return start;20 }21 }