标签:style describe scribe java col nod treenode strong 题目
二叉树的镜像定义:源二叉树 8 / 6 10 / \ / 5 7 9 11 镜像二叉树 8 / 10 6 / \ / 11 9 7 5
代码实现(Java)
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 public class Solution { 13 public void Mirror(TreeNode root) { 14 if(root==null){ 15 return; 16 } 17 if(root.left==null && root.right==null){ 18 return; 19 } 20 TreeNode node=null; 21 node=root.left; 22 root.left=root.right; 23 root.right=node; 24 if(root.left!=null){ 25 Mirror(root.left); 26 } 27 if(root.right!=null){ 28 Mirror(root.right); 29 } 30 } 31 }
标签:style describe scribe java col nod treenode strong 题目
原文地址:https://www.cnblogs.com/wangqiong/p/11762103.html