每天一道剑指offer-二叉树的镜像
- 2019 年 10 月 4 日
- 筆記
前言
今天的题目 每天的题目见github(看最新的日期): https://github.com/gzc426 具体的题目可以去牛客网对应专题去找。
昨天的题解
题目
每天一道剑指offer-二叉树的镜像 来源:牛客网对应专题
题目详述
操作给定的二叉树,将其变换为源二叉树的镜像。

题目详解
代码
public class Solution { public void Mirror(TreeNode root) { if(root == null ) return; if(root.left == null && root.right == null) return; TreeNode tempNode = root.right; root.right = root.left; root.left = tempNode; //这里三行代码进行 交换左右子树 Mirror(root.left);//对于左子树 递归调用 就是说对于左子树也进行交换 Mirror(root.right);//右子树同理 } }
代码截图(避免乱码)
