My simple solution


  • 0
    V
    class Solution {
    public:
        void flatten(TreeNode* root) {
            TreeNode *move = root;
            TreeNode *serchR = nullptr;
            while( move )
            {
                if( move->left )
                {
                    if( move->right )
                    {
                        serchR = move->left;
                        while( serchR->right )
                            serchR = serchR->right;
                        serchR->right = move->right;
                    }
                    move->right = move->left;
                    move->left = nullptr;
                }
                move = move->right;
            }
    };

Log in to reply
 

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