【剑指Offer】二叉树的镜像 Posted on 2017-05-14 | In Algorithm , 剑指Offer 题目请完成一个函数,输入一个二叉树,该函数输出它的镜像。 实现123456789public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }} 12345678910111213public void Mirror(TreeNode root) { if (root == null) return; else if (root.left == null && root.right == null) return; TreeNode tmp = root.left; root.left = root.right; root.right = tmp; Mirror(root.left); Mirror(root.right);}