c++ recursive solution beat 100%

  • 0
    class Solution {
        void helper(TreeNode * root, int & last){
            if(root==NULL) return;
            helper(root->right, last);
            root->val += last;
            last = root->val;
            helper(root->left, last);
        TreeNode* convertBST(TreeNode* root) {
            int last=0;
            helper(root, last);
            return root;

Log in to reply

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