LeetCode知识点总结-538-创新互联
                                            
                                                LeetCode 538. Convert BST to Greater Tree
题目
名称栏目:LeetCode知识点总结-538-创新互联
转载来源:http://www.cqwzjz.cn/article/csicpi.html
                                            
                                        | 考点 | 难度 | 
|---|---|
| DFS | Medium | 
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.

As a reminder, a binary search tree is a tree that satisfies these constraints:
The left subtree of a node contains only nodes with keys less than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
Both the left and right subtrees must also be binary search trees.
inverse traversal
答案class Solution(object):
    def convertBST(self, root):
        self.val = 0
        def visit(root):
            if root:
                visit(root.right)
                root.val += self.val
                self.val = root.val
                visit(root.left)
        visit(root)
        return root你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
名称栏目:LeetCode知识点总结-538-创新互联
转载来源:http://www.cqwzjz.cn/article/csicpi.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 