leetcode-cpp 114.二叉树展开为链表

114.二叉树展开为链表

  • 题目:

在这里插入图片描述

  • 链接

    leetcode

  • solution:

    原地展开嗷 后序遍历! 一开始还想了很多 哇原来后续遍历就行

  • code


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

猜你喜欢

转载自blog.csdn.net/weixin_43255713/article/details/105524512