mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-13 07:35:47 +08:00
Add typing annotations to Python codes. (#411)
This commit is contained in:
@@ -80,7 +80,7 @@
|
||||
""" 初始化队列 """
|
||||
# 在 Python 中,我们一般将双向队列类 deque 看作队列使用
|
||||
# 虽然 queue.Queue() 是纯正的队列类,但不太好用,因此不建议
|
||||
que = collections.deque()
|
||||
que: Deque[int] = collections.deque()
|
||||
|
||||
""" 元素入队 """
|
||||
que.append(1)
|
||||
@@ -90,16 +90,16 @@
|
||||
que.append(4)
|
||||
|
||||
""" 访问队首元素 """
|
||||
front = que[0];
|
||||
front: int = que[0];
|
||||
|
||||
""" 元素出队 """
|
||||
pop = que.popleft()
|
||||
pop: int = que.popleft()
|
||||
|
||||
""" 获取队列的长度 """
|
||||
size = len(que)
|
||||
size: int = len(que)
|
||||
|
||||
""" 判断队列是否为空 """
|
||||
is_empty = len(que) == 0
|
||||
is_empty: bool = len(que) == 0
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
|
||||
Reference in New Issue
Block a user