mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-01 17:53:18 +08:00
build
This commit is contained in:
@@ -98,7 +98,7 @@ $$
|
||||
=== "Python"
|
||||
|
||||
```python title="binary_search.py"
|
||||
def binary_search(nums: List[int], target: int) -> int:
|
||||
def binary_search(nums: list[int], target: int) -> int:
|
||||
""" 二分查找(双闭区间) """
|
||||
# 初始化双闭区间 [0, n-1] ,即 i, j 分别指向数组首元素、尾元素
|
||||
i, j = 0, len(nums) - 1
|
||||
@@ -309,7 +309,7 @@ $$
|
||||
=== "Python"
|
||||
|
||||
```python title="binary_search.py"
|
||||
def binary_search1(nums: List[int], target: int) -> int:
|
||||
def binary_search1(nums: list[int], target: int) -> int:
|
||||
""" 二分查找(左闭右开) """
|
||||
# 初始化左闭右开 [0, n) ,即 i, j 分别指向数组首元素、尾元素+1
|
||||
i, j = 0, len(nums)
|
||||
|
||||
@@ -45,7 +45,7 @@ comments: true
|
||||
=== "Python"
|
||||
|
||||
```python title="hashing_search.py"
|
||||
def hashing_search_array(mapp: Dict[int, int], target: int) -> int:
|
||||
def hashing_search_array(mapp: dict[int, int], target: int) -> int:
|
||||
""" 哈希查找(数组) """
|
||||
# 哈希表的 key: 目标元素,value: 索引
|
||||
# 若哈希表中无此 key ,返回 -1
|
||||
@@ -163,7 +163,7 @@ comments: true
|
||||
=== "Python"
|
||||
|
||||
```python title="hashing_search.py"
|
||||
def hashing_search_linkedlist(mapp: Dict[int, ListNode], target: int) -> Optional[ListNode]:
|
||||
def hashing_search_linkedlist(mapp: dict[int, ListNode], target: int) -> ListNode | None:
|
||||
""" 哈希查找(链表) """
|
||||
# 哈希表的 key: 目标元素,value: 结点对象
|
||||
# 若哈希表中无此 key ,返回 None
|
||||
|
||||
@@ -49,7 +49,7 @@ comments: true
|
||||
=== "Python"
|
||||
|
||||
```python title="linear_search.py"
|
||||
def linear_search_array(nums: List[int], target: int) -> int:
|
||||
def linear_search_array(nums: list[int], target: int) -> int:
|
||||
""" 线性查找(数组) """
|
||||
# 遍历数组
|
||||
for i in range(len(nums)):
|
||||
@@ -206,7 +206,7 @@ comments: true
|
||||
=== "Python"
|
||||
|
||||
```python title="linear_search.py"
|
||||
def linear_search_linkedlist(head: ListNode, target: int) -> Optional[ListNode]:
|
||||
def linear_search_linkedlist(head: ListNode, target: int) -> ListNode | None:
|
||||
""" 线性查找(链表) """
|
||||
# 遍历链表
|
||||
while head:
|
||||
|
||||
Reference in New Issue
Block a user