题目:https://leetcode.com/problems/sqrtx/tabs/description
代码:
class Solution {
public:
int mySqrt(int x) {
double k=1.0;
while(fabs(k*k-x)>0.01){
k=(k+x/k)/2;
}
return int(k);
}
};
牛顿法求平方根
题目:https://leetcode.com/problems/sqrtx/tabs/description
代码:
class Solution {
public:
int mySqrt(int x) {
double k=1.0;
while(fabs(k*k-x)>0.01){
k=(k+x/k)/2;
}
return int(k);
}
};
牛顿法求平方根