public class Solution extends GuessGame {
public int guessNumber(int n) {
int low = 1, high = n;
int g = 1;
while (low <= high) {
g = low + (highlow)/2;
if(guess(g) == 0) {
break;
} else if (guess(g) == 1) {
low = g+1;
} else {
high = g;
}
}
return g;
}
}
1mS Java solution using binary search

@dadinghh2 low + high could exceed max value of integer.
use long low and long high, then g = (int) ((low + high) / 2) works