5.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:algorithm_course 作者: hrwhisper 项目源码 文件源码
def create_huffman_tree(txt):
    q = [TreeNode(c, cnt) for c, cnt in collections.Counter(txt).items()]
    heapq.heapify(q)
    while len(q) > 1:
        a, b = heapq.heappop(q), heapq.heappop(q)
        heapq.heappush(q, TreeNode('', a.cnt + b.cnt, a, b))
    return q.pop()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号