运气最好时要几步
在 [13, 15, 17, 23, 24] 里从头挨个找 13。运行下面这段程序:
def lsearch_steps(a, target):
steps = 0
for x in a:
steps += 1
if x == target:
return steps
return steps
print(lsearch_steps([13, 15, 17, 23, 24], 13))
在 [13, 15, 17, 23, 24] 里从头挨个找 13。运行下面这段程序:
def lsearch_steps(a, target):
steps = 0
for x in a:
steps += 1
if x == target:
return steps
return steps
print(lsearch_steps([13, 15, 17, 23, 24], 13))
全部评论