博文中会简要介绍Leetcode P0069题目分析及解题思路。
“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.
以下是Java的题解代码实现。
以下是C++的题解代码实现。