Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 476 Bytes

196.md

File metadata and controls

24 lines (17 loc) · 476 Bytes
@author jackzhenguo
@desc
@tag
@version 
@date 2020/04/03

196 使用堆排序列表为升序

使用 heapq 模块,首先对列表建堆,默认建立小根堆,调用len(nums) 次heapop:

import heapq as hq

nums_list = [18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1]
hq.heapify(nums_list)
s_result = [hq.heappop(nums_list) for _ in range(len(nums_list))]
print(s_result)
[上一个例子](195.md) [下一个例子](197.md)