Reverse Inorder


  • 1
    W

    class Solution {

    public:

    void helper(TreeNode* root, int & sum) {
        if (root) {
            helper(root->right, sum);
            sum += root->val;
            root->val = sum;
            helper(root->left, sum);
        }
    }
    
    TreeNode* convertBST(TreeNode* root) {
        int sum = 0;
        helper(root, sum);
        return (root);
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.