在给定的数组中如何找到第2,3,4或5个值?找到第二个最高的元素
另外,如果我们在python中使用
max()
函数,那么复杂度的顺序是什么,即与这个函数max()
有关?
。
def nth_largest(li,n):
li.remove(max(li))
print max(ele) //will give me the second largest
#how to make a general algorithm to find the 2nd,3rd,4th highest value
#n is the element to be found below the highest value
如果你有'[1,2,2]''的列表,你想要什么作为第二大元素? '1'还是'2'? – DSM
我希望它在你的情况下为1 – Hulk