1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public class Solution extends GuessGame { public int guessNumber(int n) { int begin = 1; int end = n; while(true){ int mid = begin+((end-begin)>>1); int flag = guess(mid); if(flag>0){ begin = mid+1; }else if(flag<0){ end = mid-1; }else{ return mid; } }
} }
|