LeetCode||69. Sqrt(x)

来源:互联网 发布:linux 安装2个jdk 编辑:程序博客网 时间:2024/06/18 09:24

Implement int sqrt(int x).

Compute and return the square root of x.

x is guaranteed to be a non-negative integer.


Example 1:

Input: 4Output: 2

Example 2:

Input: 8Output: 2Explanation: The square root of 8 is 2.82842..., and since we want to return an integer, the decimal part will be truncated.

取平方根,去尾法

class Solution(object):    def mySqrt(self, x):        """        :type x: int        :rtype: int        """        return int(x**.5)


原创粉丝点击