/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public TreeNode mirrorTree(TreeNode root) { //节点root为空,返回null if(root == null) return null; //交换左右节点 TreeNode temp = root.left; root.left = root.right; root.right = temp; //递归 mirrorTree(root.left); mirrorTree(root.right); return root; } }