最小值最大化int l = min_ans, r = max_ans;while (l < r) { int mid = (l + r + 1) / 2; //+1避免 r == l + 1 时mid一直等于l,从而死循环 if (ok(mid)) //符合条件返回True l = mid; else r = mid - 1;}最大值最小化int l = min_ans, r = max_ans; while (l < r) { int mid = (l + r) / 2; if (ok(mid)) //符合条件返回True r = mid; else l = mid + 1; }