Internal working of python heapq merge. How does it sort a list without generating the list

后端 未结 2 994
遥遥无期
遥遥无期 2021-01-05 18:37

How does heapq.merge() sort a list even without generate the list?

Not sure if I stated clear.
So, this is raised from the Super Ugly Number proble

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 18:51

    It takes n already sorted iterables. It can then look at the smallest value in each of those and use that. The smallest one is always the first item, then the second item, then the third item, since they are each sorted.

提交回复
热议问题