美文网首页
Flatten Binary Tree to Linked Li

Flatten Binary Tree to Linked Li

作者: DaiMorph | 来源:发表于2019-05-04 11:34 被阅读0次

    https://www.cnblogs.com/grandyang/p/4293853.html
    /
    5
    / \
    4 6

    /
    4

    \

    \
      \
        \
          \
            \
    
    class Solution {
    public:
        void flatten(TreeNode* root) {
            if(root==NULL)return;
            if(root->left)flatten(root->left);
            if(root->right)flatten(root->right);
            TreeNode*temp=root->right;
            root->right=root->left;
            root->left=NULL;
            while(root->right)root=root->right;
            root->right=temp;
        }
    };
    

    相关文章

      网友评论

          本文标题:Flatten Binary Tree to Linked Li

          本文链接:https://www.haomeiwen.com/subject/nukxoqtx.html