← 返回题库
中级

二叉搜索树转换为累加树

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve(____):
    total = ____
    def dfs(____):
        nonlocal total
        if not node:
            return
        dfs(____)
        total += node.val
        node.val = total
        dfs(____)
    dfs(____)
    return root

示例

输入
[4,1,6,0,2,5,7,null,null,null,3]
期望输出
[30,36,21,36,35,26,15,null,null,null,33]
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码