https://leetcode.com/problems/guess-number-higher-or-lower/description/
解题思路:
得到中间值去判断
public class Solution extends GuessGame {
public int guessNumber(int n) {
int left = 1;
int right = n;
while(left <= right){
int mid = (right - left) / 2 + left;
if(guess(mid) == 1){
left = mid + 1;
} else if(guess(mid) == -1){
right = mid - 1;
} else if(guess(mid) == 0){
return mid;
}
}
return 0;
}
}