leetcode114

class Solution {
public:
    void flatten(TreeNode* root) {
        while(root){
            if(root->left){
                TreeNode* pre=root->left;
                while(pre->right){
                    pre=pre->right;
                    
                }
                pre->right=root->right;
                root->right=root->left;
                root->left=nullptr;
            }
            root=root->right;
        }
    }
};

猜你喜欢

转载自www.cnblogs.com/asenyang/p/9780149.html