- 两段条件法
while( left < right ){
int mid = left + (right -left >> 1);
if( ){ //答案在左区间
right = mid;
}else{ //答案在右区间
left = mid + 1;
}
} //left == right
return left;
- 三段条件法
while( left < right ){
int mid = left + (right -left >> 1);
if( ){ //找到答案
return mid;
}else if(){ //答案在右区间
left = mid + 1;
}else if(){答案在左区间
right = mid;
}
} //left == right
return left;