Implement int
sqrt(int x)
.
Compute
and return the square root of x.
class Solution {
public:
int sqrt(
int x)
{
int i=
0;
int step=
1;
while(step>
0)
{
while((i+step)<=x/(i+step))
{
i=i+step;
step=(step<<
1);
}
step=(step>>
1);
}
return i;
}
};
Sqrt(x),布布扣,bubuko.com
Sqrt(x)
原文:http://www.cnblogs.com/erictanghu/p/3759473.html