题解 | 最大的差
最大的差
https://www.nowcoder.com/practice/0cc49c97703d471dae00b43a5649e4f9
n = int(input())
lst = list(map(int,input().split()))
# lst.sort()
# S = lst[-1] - lst[0]
# print(S)
max = min = lst[0]
for item in lst:
if max < item:
max = item
if min > item:
min = item
print(max - min)
这道题如果不用sort方法,就要注意max,min初值需要赋值成列表的第一个数,以它为基准,才能得到列表的最大,最小值
查看12道真题和解析