refactor: Follow the PEP 585 Typing standard (#439)

* Follow the PEP 585 Typing standard

* Update list.py
This commit is contained in:
Yudong Jin
2023-03-23 18:51:56 +08:00
committed by GitHub
parent f4e01ea32e
commit 8918ec9079
43 changed files with 256 additions and 342 deletions

View File

@ -4,11 +4,7 @@ Created Time: 2022-11-25
Author: Krahets (krahets@163.com)
"""
import sys, os.path as osp
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
from modules import *
def two_sum_brute_force(nums: List[int], target: int) -> List[int]:
def two_sum_brute_force(nums: list[int], target: int) -> list[int]:
""" 方法一:暴力枚举 """
# 两层循环,时间复杂度 O(n^2)
for i in range(len(nums) - 1):
@ -17,7 +13,7 @@ def two_sum_brute_force(nums: List[int], target: int) -> List[int]:
return [i, j]
return []
def two_sum_hash_table(nums: List[int], target: int) -> List[int]:
def two_sum_hash_table(nums: list[int], target: int) -> list[int]:
""" 方法二:辅助哈希表 """
# 辅助哈希表,空间复杂度 O(n)
dic = {}
@ -37,8 +33,8 @@ if __name__ == '__main__':
# ====== Driver Code ======
# 方法一
res: List[int] = two_sum_brute_force(nums, target)
res: list[int] = two_sum_brute_force(nums, target)
print("方法一 res =", res)
# 方法二
res: List[int] = two_sum_hash_table(nums, target)
res: list[int] = two_sum_hash_table(nums, target)
print("方法二 res =", res)