LeetCode —— Invert Binary Tree

struct TreeNode* invertTree(struct TreeNode* root)
{

    if ( NULL == root )
    {
        return NULL;
    }


    if ( NULL == root->left && NULL == root->right )
    {
        //叶子节点
        return root;
    }

    //交换左右子节点
    struct TreeNode * pTreeNodeTmp = root->left;

    root->left = root->right;
    root->right = pTreeNodeTmp;

    invertTree(root->left);
    invertTree(root->right);

    return root;
}

 

posted @ 2015-06-18 19:09  Jabnih  阅读(120)  评论(0编辑  收藏  举报