```
public class Solution extends GuessGame {
public int guessNumber(int n){
if(guess(1) ==0)
return 1;
if(guess(n) == 0)
return n;
int lower = 1;
int upper = n;
int current = (1 + n) >> 1;
while(guess(current) != 0){
if(guess(current) == 1)
lower = current;
if(guess(current) == -1)
upper = current;
current = lower % 2 != 0 || upper % 2 != 0 ? (lower >> 1) + (upper >> 1) + 1 : (lower >> 1) + (upper >> 1);
}
return current;
}
}
```