标签:
Implement int sqrt(int x).
Compute and return the square root of x.
求平方根
class Solution { //牛顿迭代算法
public:
int mySqrt(int x) {
if(x<2)return x;
int left = 0;
int right = x;
while(left<right)
{
right = (left+right)/2;
left = x/right;
}
return min(left,right);
}
};
标签:
原文地址:http://blog.csdn.net/u011391629/article/details/52116049