用按值二分在答案范围内搜索。记左右边界为 l 与 r。当 x≥2 时有

因此可取初始区间 [l=1,r=⌊2x⌋+1];当 x<2 时直接返回 x。
在循环中取中点
实现函数 int mysqrt(int x) 。
计算并返回 x 的平方根(向下取整)
数据范围:0<=x<231−1
Scan the QR code below with WeChat to sign in
First-time scan will create your account automatically
请使用微信扫描下方二维码完成注册