def second_max(a, low, high):
if high - low <= 1:
if a[high] > a[low]:
src = [a[high], a[low]] # 第一個元素為最大元素
else:
src = [a[low], a[high]]
return src
mid = (low + high) // 2
arr1 = second_max(a, low, mid)
arr2 = second_max(a, mid + 1, high)
if arr1[0] > arr2[0]:
src = [arr1[0], arr2[0]]
else:
src = [arr2[0], arr1[0]]
return src
def find_second_max(a, low, high):
res = second_max(a, low, high)
return res[1]
a = [5, 1, 2, 4]
res = find_second_max(a, 0, len(a) - 1)
print(res)