您的位置:首页 > 编程语言 > Python开发

python 找出list中差值最大的两个数

2016-10-13 00:00 363 查看
题目:
无序数组(list),array = [45,3,8,1,2,19,22,35,23],找到差值最大的两个点A 和 B(B-A>0),且B的索引大于A的索引;

array = [45,3,8,1,2,19,22,35,23]
new = sorted(array,reverse=False)

A = new[0]

while True:
B = new[-1]
if array.index(B) > array.index(A):
print A,B
break
else:
new.remove(B)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息