← 返回教程列表
🧮 算法与数据结构
链表与树
# 二叉树节点
class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
# 中序遍历
def inorder(root):
if root:
inorder(root.left)
print(root.val)
inorder(root.right)
# 链表节点
class ListNode:
def __init__(self, val=0):
self.val = val
self.next = None