int left = 1; int right = max; int middle = (left+right)/2; while(left < right){ if(func(piles, pilesSize, h, middle) == 0){ right = middle; }else{ left = middle+1; } middle = (left+right)/2; } return right;
注意:
循环结束条件是 left >= right
left 是 middle+1,不是middle
最终得到的值是 right