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);

    }
};


posted @ 2017-05-06 10:30  jhcelue  阅读(123)  评论(0编辑  收藏  举报