2 lines


  • -1
    Y
    int convert(struct TreeNode *curr, int val)
    {
        curr->val += curr->right != NULL ? convert(curr->right, val) : val;
        return curr->left != NULL ? convert(curr->left, curr->val) : curr->val;
    }
    struct TreeNode* convertBST(struct TreeNode *root)
    {
        if (root != NULL) {
            convert(root, 0);
        }
        return root;
    }
    

Log in to reply
 

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