剑指offer-18:二叉树的镜像

二叉树的镜像

https://www.nowcoder.com/practice/a9d0ecbacef9410ca97463e4a5c83be7?tpId=13&&tqId=11171&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking

题目:操作给定的二叉树,将其变换为源二叉树的镜像。

比如:    源二叉树 
            8
           /  \
          6   10
         / \  / \
        5  7 9 11
        镜像二叉树
            8
           /  \
          10   6
         / \  / \
        11 9 7  5

思路:
1:这道题归根到底就是左右子树递归交换.
2:直接对当前的左右子树进行交换.
3:递归左子树,递归右子树.
4:在前面加上递归的终止条件,节点为空则返回null

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务