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);
}
};
原文地址:https://www.cnblogs.com/ssml/p/9302088.html
时间: 2024-10-16 07:13:03