BiruLyu
7/10/2017 - 8:41 PM

538. Convert BST to Greater Tree.java

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