leetcode总结-- heapq运用,关于super ugly number, merge k sorted list

相关题目

merge k sorted list
http://blog.csdn.net/xyqzki/article/details/50265013

super ugly number
http://blog.csdn.net/xyqzki/article/details/50379007

heapq

这里关于heapq的运用,

对于list a,我们可以in-place, 将其transform to a min heap. 注意是in place

import heapq
heapq.heapify(a)

这个时候a[0]就是min了。但是如果要pop掉这个min就要使用heappop

m = heapq.heappop(a)

然后如果要加入新的值到a中,update这个min heap,要用heappush将c加入到a中

heapq.heappush(a, c)

你可能感兴趣的:(leetcode总结-- heapq运用,关于super ugly number, merge k sorted list)