本文共 328 字,大约阅读时间需要 1 分钟。
Implement int sqrt(int x)
.
Compute and return the square root of x.
class Solution {public: int sqrt(int x) { double esp = 1e-5; if(x == 0) return 0; double x0 = x; double x1; do{ x1 = x0; x0 = (x0 + x/x0)/2; }while(abs(x0 - x1) > esp); return x1; }};
转载地址:http://eelji.baihongyu.com/