class Solution {
public:
int mySqrt(int x
) {
int left
= 0, right
= x
/ 2 + 1;
int res
= 0;
while (left
<= right
) {
int mid
= (left
+ right
) >> 1;
if (((long long) mid
* mid
<= x
)) {
left
= mid
+ 1;
res
= mid
;
}
else {
right
= mid
- 1;
}
}
return res
;
}
};
转载请注明原文地址:https://tech.qufami.com/read-9153.html