mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-03 02:43:41 +08:00
Add typing annotations to Python codes. (#411)
This commit is contained in:
@@ -81,7 +81,7 @@
|
||||
```python title="stack.py"
|
||||
""" 初始化栈 """
|
||||
# Python 没有内置的栈类,可以把 List 当作栈来使用
|
||||
stack = []
|
||||
stack: List[int] = []
|
||||
|
||||
""" 元素入栈 """
|
||||
stack.append(1)
|
||||
@@ -91,16 +91,16 @@
|
||||
stack.append(4)
|
||||
|
||||
""" 访问栈顶元素 """
|
||||
peek = stack[-1]
|
||||
peek: int = stack[-1]
|
||||
|
||||
""" 元素出栈 """
|
||||
pop = stack.pop()
|
||||
pop: int = stack.pop()
|
||||
|
||||
""" 获取栈的长度 """
|
||||
size = len(stack)
|
||||
size: int = len(stack)
|
||||
|
||||
""" 判断是否为空 """
|
||||
is_empty = len(stack) == 0
|
||||
is_empty: bool = len(stack) == 0
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
|
||||
Reference in New Issue
Block a user