标签:二叉树的镜像 int color nod his desc tree 定义 二叉树
二叉树的镜像定义:源二叉树 8 / 6 10 / \ / 5 7 9 11 镜像二叉树 8 / 10 6 / \ / 11 9 7 5
1 /** 2 public class TreeNode { 3 int val = 0; 4 TreeNode left = null; 5 TreeNode right = null; 6 7 public TreeNode(int val) { 8 this.val = val; 9 10 } 11 12 } 13 */ 14 public class Solution { 15 public void Mirror(TreeNode root) { 16 TreeNode temp; 17 if(root != null) { 18 temp = root.left; 19 root.left = root.right; 20 root.right = temp; 21 if(root.left != null){ 22 Mirror(root.left); 23 } 24 if(root.right != null){ 25 Mirror(root.right); 26 } 27 } 28 } 29 }
标签:二叉树的镜像 int color nod his desc tree 定义 二叉树
原文地址:https://www.cnblogs.com/yihangZhou/p/10332177.html