def get_min(li):
low = 0
high = len(li) - 1
mid = low
while li[low] >= li[high]: # 一般low的元素>=high的元素
if high - low == 1:
mid = high
break
if (li[low] == li[high] and li[mid] == li[low]): # 特殊情况:无法判断 mid位于左子数组还是右子数组
return get_min_order(li)
mid = (low + high) // 2
if li[mid] >= li[low]: # 如果mid大于low位置的元素,则最小值应该在mid 的后面
low = mid
elif li[mid] <= li[high]: # 如果mid小于于high位置的元素,则最小值应该在mid 的前面
high = mid
return li[mid]
def get_min_order(li):
# 顺序查找
min = li[0]
for i in li:
if i < min:
min = i
return min
li = [4, 5, 6,1, 2, 3]
print(get_min(li))