剑指 Offer 第27题:二叉树的镜像
2022-07-18 本文已影响0人
放开那个BUG
1、前言
![](https://img.haomeiwen.com/i11345146/5dcd18b5da4cbe3c.png)
2、思路
3、代码
class Solution {
public TreeNode mirrorTree(TreeNode root) {
if(root == null){
return root;
}
mirrorTree(root.left);
mirrorTree(root.right);
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
return root;
}
}