beats 100% c++ solution


  • 0
    I
    class Solution {
    public:
        void Travel(TreeNode* root, int& score) {
            if (!root) return;
            if (root->right) Travel(root->right, score);
            int val = root->val;
            root->val += score;
            score += val;
            if (root->left) Travel(root->left, score);
        }
    
        TreeNode* convertBST(TreeNode* root) {
            int score = 0;
            Travel(root, score);
            return root;
        }
    };
    

Log in to reply
 

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