![](/img/trans.png)
[英]Given a list of numbers in random order, write an algorithm that works in O(nlog(n)) to find the kth smallest number in the list
[英]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.