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.
實作
int sqrt(int x)
。
計算並回傳 x 的平方根,x是非負整數。
因為回傳的型態是一個整數,小數點之後的部分請全部捨去,只留下並回傳整數部分。
double
去處理。0
的時候會出問題,要特別處理。floor()
即可。LeetCode
C++