教程导航

陆伍
11小时前发布 /正在检测是否收录...
← 返回教程列表

🧮 算法与数据结构

链表与树

# 二叉树节点
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
评论 抢沙发
OωO
取消