【剑指offer】18 二叉树的镜像

题目地址:二叉树的镜像

题目描述                                   

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

题目示例                                   

二叉树的镜像定义:源二叉树 
    	    8
    	   /  
    	  6   10
    	 /   / 
    	5  7 9 11
    	镜像二叉树
    	    8
    	   /  
    	  10   6
    	 /   / 
    	11 9 7  5

解法分析                                   

利用递归,翻转左右子节点。

代码                                         

1 function Mirror(root)
2 {
3     // write code here
4     if(root === null) return;
5     Mirror(root.left);
6     Mirror(root.right);
7     [root.left, root.right] = [root.right, root.left]
8     return root;
9 }

执行结果                                   

原文地址:https://www.cnblogs.com/sunlinan/p/14296364.html