繁体   English   中英

给定一个包含 N 个数字的列表,如何找到最大数字必须移动才能到达列表末尾的索引数量

[英]Given a list of N numbers, how to find the number of indices the maximum number will have to move in order to reach end of list

找到最大数量后如何转到列表的末尾?

输入:1

5

3 5 2 4 2

输出 :

3

您可以使用list.index()max(list)来获取最大值的索引,然后从列表的长度中减去它以获得它必须移动的距离:

>>> a = [3, 5, 2, 4, 2]
>>> len(a) - (a.index(max(a)) + 1)
3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM