mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Simplify the declarations of the Python code.
This commit is contained in:
@ -430,12 +430,12 @@
|
||||
|
||||
```python title="list.py"
|
||||
# 通过索引遍历列表
|
||||
count: int = 0
|
||||
count = 0
|
||||
for i in range(len(list)):
|
||||
count += 1
|
||||
|
||||
# 直接遍历列表元素
|
||||
count: int = 0
|
||||
count = 0
|
||||
for n in list:
|
||||
count += 1
|
||||
```
|
||||
|
||||
@ -87,10 +87,10 @@
|
||||
return 0
|
||||
|
||||
def algorithm(n) -> int: # 输入数据
|
||||
A: int = 0 # 暂存数据(常量,一般用大写字母表示)
|
||||
b: int = 0 # 暂存数据(变量)
|
||||
A = 0 # 暂存数据(常量,一般用大写字母表示)
|
||||
b = 0 # 暂存数据(变量)
|
||||
node = Node(0) # 暂存数据(对象)
|
||||
c: int = function() # 栈帧空间(调用函数)
|
||||
c = function() # 栈帧空间(调用函数)
|
||||
return A + b + c # 输出数据
|
||||
```
|
||||
|
||||
@ -293,10 +293,10 @@
|
||||
|
||||
```python title=""
|
||||
def algorithm(n: int) -> None:
|
||||
a: int = 0 # O(1)
|
||||
b: List[int] = [0] * 10000 # O(1)
|
||||
a = 0 # O(1)
|
||||
b = [0] * 10000 # O(1)
|
||||
if n > 10:
|
||||
nums: List[int] = [0] * n # O(n)
|
||||
nums = [0] * n # O(n)
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
|
||||
@ -415,7 +415,7 @@ $$
|
||||
|
||||
```python title=""
|
||||
def algorithm(n: int) -> None:
|
||||
a: int = 1 # +1
|
||||
a = 1 # +1
|
||||
a = a + 1 # +1
|
||||
a = a * 2 # +1
|
||||
# 循环 n 次
|
||||
@ -604,8 +604,8 @@ $$
|
||||
|
||||
```python title=""
|
||||
def algorithm(n: int) -> None:
|
||||
a: int = 1 # +0(技巧 1)
|
||||
a = a + n # +0(技巧 1)
|
||||
a = 1 # +0(技巧 1)
|
||||
a = a + n # +0(技巧 1)
|
||||
# +n(技巧 2)
|
||||
for i in range(5 * n + 1):
|
||||
print(0)
|
||||
@ -619,7 +619,7 @@ $$
|
||||
|
||||
```go title=""
|
||||
func algorithm(n int) {
|
||||
a := 1 // +0(技巧 1)
|
||||
a := 1 // +0(技巧 1)
|
||||
a = a + n // +0(技巧 1)
|
||||
// +n(技巧 2)
|
||||
for i := 0; i < 5 * n + 1; i++ {
|
||||
|
||||
Reference in New Issue
Block a user