[leetcode] 69. Sqrt(x) 解题报告

Implement int sqrt(int x).

Compute and return the square root of x.

 using only integer division for the Newton method works

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

 

posted @ 2017-09-26 22:44  pulusite  阅读(104)  评论(0)    收藏  举报