mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-16 03:59:18 +08:00
Simplify the declarations of the Python code.
This commit is contained in:
@@ -40,8 +40,8 @@ def binary_search_lcro(nums: list[int], target: int) -> int:
|
||||
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
target: int = 6
|
||||
nums: list[int] = [1, 3, 6, 8, 12, 15, 23, 26, 31, 35]
|
||||
target = 6
|
||||
nums = [1, 3, 6, 8, 12, 15, 23, 26, 31, 35]
|
||||
|
||||
# 二分查找(双闭区间)
|
||||
index: int = binary_search(nums, target)
|
||||
|
||||
@@ -41,8 +41,8 @@ def binary_search_right_edge(nums: list[int], target: int) -> int:
|
||||
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
target: int = 6
|
||||
nums: list[int] = [1, 3, 6, 6, 6, 6, 6, 10, 12, 15]
|
||||
target = 6
|
||||
nums = [1, 3, 6, 6, 6, 6, 6, 10, 12, 15]
|
||||
|
||||
# 二分查找最左一个元素
|
||||
index_left = binary_search_left_edge(nums, target)
|
||||
|
||||
@@ -28,10 +28,10 @@ def hashing_search_linkedlist(
|
||||
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
target: int = 3
|
||||
target = 3
|
||||
|
||||
# 哈希查找(数组)
|
||||
nums: list[int] = [1, 5, 3, 2, 4, 7, 5, 9, 10, 8]
|
||||
nums = [1, 5, 3, 2, 4, 7, 5, 9, 10, 8]
|
||||
# 初始化哈希表
|
||||
map0 = dict[int, int]()
|
||||
for i in range(len(nums)):
|
||||
|
||||
@@ -31,10 +31,10 @@ def linear_search_linkedlist(head: ListNode, target: int) -> ListNode | None:
|
||||
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
target: int = 3
|
||||
target = 3
|
||||
|
||||
# 在数组中执行线性查找
|
||||
nums: list[int] = [1, 5, 3, 2, 4, 7, 5, 9, 10, 8]
|
||||
nums = [1, 5, 3, 2, 4, 7, 5, 9, 10, 8]
|
||||
index: int = linear_search_array(nums, target)
|
||||
print("目标元素 3 的索引 =", index)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user