LeetCode 226. Invert Binary Tree

226. Invert Binary Tree

其实就是个前序遍历

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

猜你喜欢

转载自blog.csdn.net/weixin_41256413/article/details/82708856