feat: Add visualizing code blocks based on the pythontutor (#1029)

* Update copyright

* Update the Python code

* Fix the code comments in ArrayBinaryTree

* Fix the code comments in ArrayBinaryTree

* Roll back time_comlexity.py

* Add the visualizing code(pythontutor) blocks to the chapter complexity, data structure, array and linked list, stack and queue, hash table, and backtracking

* Fix the code comments
This commit is contained in:
Yudong Jin
2024-01-07 04:04:01 +08:00
committed by GitHub
parent 0f5b924036
commit ddd375af20
61 changed files with 434 additions and 40 deletions

View File

@ -6,7 +6,7 @@ Author: Krahets (krahets@163.com)
class ListNode:
"""Definition for a singly-linked list node"""
"""链表节点类"""
def __init__(self, val: int):
self.val: int = val # 节点值
@ -14,7 +14,7 @@ class ListNode:
def list_to_linked_list(arr: list[int]) -> ListNode | None:
"""Generate a linked list with a list"""
"""将列表序列化为链表"""
dum = head = ListNode(0)
for a in arr:
node = ListNode(a)
@ -24,16 +24,9 @@ def list_to_linked_list(arr: list[int]) -> ListNode | None:
def linked_list_to_list(head: ListNode | None) -> list[int]:
"""Serialize a linked list into an array"""
"""将链表反序列化为列表"""
arr: list[int] = []
while head:
arr.append(head.val)
head = head.next
return arr
def get_list_node(head: ListNode | None, val: int) -> ListNode | None:
"""Get a list node with specific value from a linked list"""
while head and head.val != val:
head = head.next
return head