This commit is contained in:
krahets
2023-03-23 18:56:56 +08:00
parent 2715ce703a
commit 0dfdcf0bab
25 changed files with 118 additions and 115 deletions

View File

@@ -412,7 +412,7 @@ comments: true
""" 基于链表实现的栈 """
def __init__(self):
""" 构造方法 """
self.__peek: Optional[ListNode] = None
self.__peek: ListNode | None = None
self.__size: int = 0
def size(self) -> int:
@@ -443,9 +443,9 @@ comments: true
if not self.__peek: return None
return self.__peek.val
def to_list(self) -> List[int]:
def to_list(self) -> list[int]:
""" 转化为列表用于打印 """
arr: List[int] = []
arr: list[int] = []
node = self.__peek
while node:
arr.append(node.val)
@@ -954,7 +954,7 @@ comments: true
""" 基于数组实现的栈 """
def __init__(self) -> None:
""" 构造方法 """
self.__stack: List[int] = []
self.__stack: list[int] = []
def size(self) -> int:
""" 获取栈的长度 """
@@ -978,7 +978,7 @@ comments: true
assert not self.is_empty(), "栈为空"
return self.__stack[-1]
def to_list(self) -> List[int]:
def to_list(self) -> list[int]:
""" 返回列表用于打印 """
return self.__stack
```