```
public class Solution extends GuessGame {
public int guessNumber(int n) {
if(n==1) return 1;
int lower = 1;
int higher = n;
int result;
while(true){
result = lower+(higher-lower)/2;
if(guess(result)==0) break;
else if(guess(result)==1){
if(result==n-1) return n;
lower = result;
}
else higher = result;
}
return result;
}
}
```