银河出逃时
2021-02-05 18:07
采纳率: 88.2%
浏览 31
已结题

Python递归函数二分查找代码出错,求大佬帮忙看看怎么修改

# 使用递归函数实现列表的二分查找
def seek(n,list,l = 0,r = len(list) - 1):
    while l <= r:
        mid = (l+r)//2
        if list[mid] > n:
            return seek(n,list,l = 0,r = mid - 1)
        elif list[mid] < n:
            return seek(n,list,l = mid + 1,r = len(list) - 1 )
        else:
            break
    print(mid)
seek(47,[4,11,23,34,47,56,75,88,98,102,122,135],l = 0,r = len(list) - 1 )
# TypeError: object of type 'type' has no len()

2条回答 默认 最新

相关推荐 更多相似问题