测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A26849. 下面Python代码用于在升序lst(list类型)中查找目标值target最后一次出现的位置。相关说法,正确的是( )。def binary_search(lst, target): if len(lst) == 0: return None low, high = 0, len(lst)-1 while low < high: mid = (low + high + 1) // 2 # 向上…

单选题 困难

题目描述

下面Python代码用于在升序lst(list类型)中查找目标值target最后一次出现的位置。相关说法,正确的是(    )。

def binary_search(lst, target):
	if len(lst) == 0:
		return None
	low, high = 0, len(lst)-1
	while low < high:
		mid = (low + high + 1) // 2 # 向上取整
		if lst[mid] <= target:
			low = mid
		else:
			high = mid - 1
	return low if lst[low] == target else None

选项(单选)

上一题 下一题