LeetCode-sqrtx

Implementint sqrt(int x).

Compute and return the square root of x.

public class Solution {
    public int sqrt(int x) {
        long r = x;
        while(r*r>x)
            r = (r+x/r)/2;
        return (int)r;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42146769/article/details/89061298