首页 > 代码库 > 69. Sqrt(x)(LeetCode)

69. Sqrt(x)(LeetCode)

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 };

 

69. Sqrt(x)(LeetCode)