题解 | #求平方根#
求平方根
http://www.nowcoder.com/practice/09fbfb16140b40499951f55113f2166c
class Solution {
public:
/**
*
* @param x int整型
* @return int整型
*/
int sqrt(int x) {
// write code here
int l = 0, r = x;
while (l < r) {
int mid = (long long) l + r + 1 >> 1;
if ((long long) mid * mid > x) {
r = mid - 1;
} else {
l = mid;
}
}
return l;
}
};