首页 > 代码库 > Invert Binary Tree

Invert Binary Tree

该题比較简单。递归交换每个节点的左右子树就可以。

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

    }
};


Invert Binary Tree