二叉树的镜像

题目

https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/

解法

递归 只用考虑一层的问题;定义好 终止条件

1
2
3
4
5
6
7
public TreeNode mirrorTree(TreeNode root) {
if (root == null) return null;
TreeNode temp = root.left;
root.left = mirrorTree(root.right);
root.right = mirrorTree(temp);
return root;
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×