Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 656 Bytes

File metadata and controls

28 lines (26 loc) · 656 Bytes
/**
 * https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/
 */
public class T938 {
    public static void main(String[] a) {
    }

    /**
     * Definition for a binary tree node. public class TreeNode { int val; TreeNode
     * left; TreeNode right; TreeNode(int x) { val = x; } }
     */
    class Solution {
        int sum=0;
        public TreeNode bstToGst(TreeNode root) {
            if(root==null){
                return null;
            }
            bstToGst(root.right);
            root.val+=sum;
            sum=root.val;
            bstToGst(root.left);
            return root;
        }
       
    }
}