c++ solution


  • 0
    B
    class Solution {
    public:
        TreeNode *p;
        
        void flatten(TreeNode* root) {
            if(!root) return ;
            
            TreeNode *right=root->right;
            if(root->left){
                flatten(root->left);
                // p is most left child
                p->right=root->right;
                root->right=root->left;
                root->left=NULL;
            }
            
            p=root;
            
            flatten(root->right);
            
        }
    };
    

Log in to reply
 

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