實現 int sqrt(int x) 函數。
計算並返回 x 的平方根,其中 x 是非負整數。
由於返回類型是整數,結果只保留整數的部分,小數部分將被捨去。
示例 1:
輸入: 4
輸出: 2
class Solution(object):
def mySqrt(self, x):
"""
:type x: int
:rtype: int
"""
return int(sqrt(x))
實現 int sqrt(int x) 函數。
計算並返回 x 的平方根,其中 x 是非負整數。
由於返回類型是整數,結果只保留整數的部分,小數部分將被捨去。
示例 1:
輸入: 4
輸出: 2
class Solution(object):
def mySqrt(self, x):
"""
:type x: int
:rtype: int
"""
return int(sqrt(x))