Retrieve the two highest item from a list containing 100,000 integers

后端 未结 15 783
心在旅途
心在旅途 2020-12-13 17:55

How can retrieve the two highest item from a list containing 100,000 integers without having to sort the entire list first?

15条回答
  •  北海茫月
    2020-12-13 18:11

    Without sorting the list the only way to really do it is to iterate through the whole list and save the highest two numbers. I think you'd be better off sorting the list.

提交回复
热议问题