Add typing annotations to Python codes. (#411)

This commit is contained in:
Yudong Jin
2023-03-12 18:49:52 +08:00
committed by GitHub
parent 2029d2b939
commit 9151eaf533
50 changed files with 577 additions and 817 deletions

View File

@@ -133,7 +133,7 @@
heapq.heappush(max_heap, flag * 4)
""" 获取堆顶元素 """
peek = flag * max_heap[0] # 5
peek: int = flag * max_heap[0] # 5
""" 堆顶元素出堆 """
# 出堆元素会形成一个从大到小的序列
@@ -144,13 +144,13 @@
val = flag * heapq.heappop(max_heap) # 1
""" 获取堆大小 """
size = len(max_heap)
size: int = len(max_heap)
""" 判断堆是否为空 """
is_empty = not max_heap
is_empty: bool = not max_heap
""" 输入列表并建堆 """
min_heap = [1, 3, 2, 5, 4]
min_heap: List[int] = [1, 3, 2, 5, 4]
heapq.heapify(min_heap)
```