LeeCode from 0 —— 69. Sqrt(x)
69. Sqrt(x)
Implement int sqrt(int x)
.
Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.
C++代码如下:
class Solution {
public:
int mySqrt(int x) {
double s;
s=sqrt(x);
return int(s);
}
};