mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-16 03:59:18 +08:00
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点 Update the footnotes in the figures * Update mindmap * Reduce the size of the mindmap.png
This commit is contained in:
@@ -16,7 +16,7 @@ def hashing_search_array(mapp: dict[int, int], target: int) -> int:
|
||||
|
||||
def hashing_search_linkedlist(mapp: dict[int, ListNode], target: int) -> ListNode | None:
|
||||
""" 哈希查找(链表) """
|
||||
# 哈希表的 key: 目标元素,value: 结点对象
|
||||
# 哈希表的 key: 目标元素,value: 节点对象
|
||||
# 若哈希表中无此 key ,返回 None
|
||||
return mapp.get(target, None)
|
||||
|
||||
@@ -39,7 +39,7 @@ if __name__ == '__main__':
|
||||
# 初始化哈希表
|
||||
map1 = dict[int, ListNode]()
|
||||
while head:
|
||||
map1[head.val] = head # key: 结点值,value: 结点
|
||||
map1[head.val] = head # key: 节点值,value: 节点
|
||||
head = head.next
|
||||
node: ListNode = hashing_search_linkedlist(map1, target)
|
||||
print("目标结点值 3 的对应结点对象为", node)
|
||||
print("目标节点值 3 的对应节点对象为", node)
|
||||
|
||||
@@ -20,10 +20,10 @@ def linear_search_linkedlist(head: ListNode, target: int) -> ListNode | None:
|
||||
""" 线性查找(链表) """
|
||||
# 遍历链表
|
||||
while head:
|
||||
if head.val == target: # 找到目标结点,返回之
|
||||
if head.val == target: # 找到目标节点,返回之
|
||||
return head
|
||||
head = head.next
|
||||
return None # 未找到目标结点,返回 None
|
||||
return None # 未找到目标节点,返回 None
|
||||
|
||||
|
||||
""" Driver Code """
|
||||
@@ -38,4 +38,4 @@ if __name__ == '__main__':
|
||||
# 在链表中执行线性查找
|
||||
head: ListNode = list_to_linked_list(nums)
|
||||
node: ListNode | None = linear_search_linkedlist(head, target)
|
||||
print("目标结点值 3 的对应结点对象为", node)
|
||||
print("目标节点值 3 的对应节点对象为", node)
|
||||
|
||||
Reference in New Issue
Block a user