Easy and short C++ Solution


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

Log in to reply
 

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