题解 | 最大的差

最大的差

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初值需要赋值成列表的第一个数,以它为基准,才能得到列表的最大,最小值

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务