顺序查找(线性查找)

博客地址:https://www.cnblogs.com/zylyehuo/

时间复杂度:O(n)

# _*_coding:utf-8_*_

def linear_search(li, val):
    for ind, v in enumerate(li):
        if v == val:
            return ind
    else:
        return None

li = list(range(1000))
print(linear_search(li, 389))

posted @ 2023-08-11 17:35  zylyehuo  阅读(7)  评论(0编辑  收藏  举报