二叉树的镜像

 1 public class Solution {
 2 
 3     public static void MirrorBinaryTree(TreeNode root) {
 4         if(root == null) {
 5             return;
 6         }
 7 
 8         if(root.left == null && root.right == null) {
 9             return;
10         }
11 
12         TreeNode tmp = root.left;
13         root.left = root.right;
14         root.right = tmp;
15 
16         if(root.left != null) {
17             MirrorBinaryTree(root.left);
18         }
19 
20         if(root.right != null) {
21             MirrorBinaryTree(root.right);
22         }
23     }
24 }

 

posted @ 2019-03-02 17:31  林木声  阅读(95)  评论(0编辑  收藏  举报