求解某个数的平方根

一个数的平方根在1~x-1内

def find_sqrt_int(num):
    if not num:
        return
    left, right = 0, num
    while left <= right:
        mid = left + (right-left) / 2
        if mid ** 2 >= num:
            index = mid
            right = mid -1
        else:
            left = mid + 1
    return int(index)


if __name__ == '__main__':
    print(find_sqrt_int([]))

 

posted @ 2021-04-23 15:52  今夜无风  阅读(75)  评论(0编辑  收藏  举报