python - 给定数组arr,长度len,求满足0<=a<=b<len时。arr[b]-arr[a]的最大值
PHPz
PHPz 2017-04-17 15:52:34
0
2
821

如题,求python代码一行实现

PHPz
PHPz

学习是最好的投资!

reply all(2)
伊谢尔伦

a = your_list

max(a[j] - a[i] for i in range(len(a)) for j in range(i, len(a)))

update

max(max(a[i:]) - a[i] for i in range(len(a)))
Peter_Zhu
max(arr[b] - arr[a] for b in range(len) for a in range(b+1))

Oh, by the way, I am writing Python 3. If you use Python 2, it is better to use xrange instead.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!