二分法溢出的情况:
public int guessNumber(int n) {
int leftP = 1;
int rightP = n;
int mid = 0;
while(leftP < rightP){
//皆是因为mid = (rightP + leftP) /2;
mid = leftP + (rightP - leftP) / 2;
if(guess(mid) == 0){
return mid;
}else if(guess(mid) == -1){
rightP = mid;
}else if(guess(mid) == 1){
leftP = mid + 1;
}
}
return rightP;
}
标签:guess,rightP,int,mid,return,images,leftP
From: https://www.cnblogs.com/MR---Zhao/p/16747698.html