mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 22:34:18 +08:00
Simplify the declarations of the Python code.
This commit is contained in:
@ -19,12 +19,12 @@ def function() -> int:
|
||||
def constant(n: int) -> None:
|
||||
"""常数阶"""
|
||||
# 常量、变量、对象占用 O(1) 空间
|
||||
a: int = 0
|
||||
nums: list[int] = [0] * 10000
|
||||
a = 0
|
||||
nums = [0] * 10000
|
||||
node = ListNode(0)
|
||||
# 循环中的变量占用 O(1) 空间
|
||||
for _ in range(n):
|
||||
c: int = 0
|
||||
c = 0
|
||||
# 循环中的函数占用 O(1) 空间
|
||||
for _ in range(n):
|
||||
function()
|
||||
@ -33,7 +33,7 @@ def constant(n: int) -> None:
|
||||
def linear(n: int) -> None:
|
||||
"""线性阶"""
|
||||
# 长度为 n 的列表占用 O(n) 空间
|
||||
nums: list[int] = [0] * n
|
||||
nums = [0] * n
|
||||
# 长度为 n 的哈希表占用 O(n) 空间
|
||||
mapp = dict[int, str]()
|
||||
for i in range(n):
|
||||
@ -51,7 +51,7 @@ def linear_recur(n: int) -> None:
|
||||
def quadratic(n: int) -> None:
|
||||
"""平方阶"""
|
||||
# 二维列表占用 O(n^2) 空间
|
||||
num_matrix: list[list[int]] = [[0] * n for _ in range(n)]
|
||||
num_matrix = [[0] * n for _ in range(n)]
|
||||
|
||||
|
||||
def quadratic_recur(n: int) -> int:
|
||||
@ -59,7 +59,7 @@ def quadratic_recur(n: int) -> int:
|
||||
if n <= 0:
|
||||
return 0
|
||||
# 数组 nums 长度为 n, n-1, ..., 2, 1
|
||||
nums: list[int] = [0] * n
|
||||
nums = [0] * n
|
||||
return quadratic_recur(n - 1)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user