O(n^2) algorithm:
In [79]: alist=[-45,0,3,10,90,5,-2,4,18,45,100,1,-266,706]
In [80]: max(n for n in alist if n!=max(alist))
Out[80]: 100
O(n) algorithm:
In [81]: alist=[-45,0,3,10,90,5,-2,4,18,45,100,1,-266,706]
In [82]: M = max(alist)
In [83]: max(n for n in alist if n!=M)
Out[83]: 100
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…