标签:pre 变换 ret return turn nod 二叉树的镜像 val ==
操作给定的二叉树,将其变换为源二叉树的镜像
/** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { public void Mirror(TreeNode root) { if(root == null){ return; } if(root.left == null && root.right == null) { return; }
//根节点交换左右 TreeNode temp = null; temp = root.right; root.right = root.left; root.left = temp; if(root.left != null) {
//换成左节点 Mirror(root.left); } if(root.right != null) {
//换成右节点 Mirror(root.right); } } }
标签:pre 变换 ret return turn nod 二叉树的镜像 val ==
原文地址:https://www.cnblogs.com/wzQingtTian/p/10662325.html