Implement int sqrt(int x).

Compute and return the square root of x.

1 class Solution {
2 public:
3     int mySqrt(int x) {
4          long r = x;
5     while (r*r > x)
6         r = (r + x/r) / 2;
7     return r;
8     }
9 };

 

posted on 2017-07-16 22:12  无惧风云  阅读(118)  评论(0)    收藏  举报