LeetCode : Sqrt(x)

来源:互联网 发布:java反射获取对象属性 编辑:程序博客网 时间:2024/05/21 17:50

Implement int sqrt(int x).

Compute and return the square root of x.

class Solution {public:    int mySqrt(int x) {        long r = x;        while (r*r > x)            r = (r + x/r) / 2;        return r;     }};
0 0
原创粉丝点击