剑指 Offer 27. 二叉树的镜像

/**
 * 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;
    }
}
原文地址:https://www.cnblogs.com/peanut-zh/p/14134663.html