二叉树的镜像
2017-09-21 11:20
134 查看
操作给定的二叉树,将其变换为源二叉树的镜像。
思路:从上到下交换每个结点的左右子树即可。
思路:从上到下交换每个结点的左右子树即可。
/** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { public void Mirror(TreeNode root) { if(root == null) return; TreeNode temp = root.left; root.left = root.right; root.right = temp; Mirror(root.left); Mirror(root.right); } }
相关文章推荐
- 剑指offer-二叉树的镜像
- 剑指offer 4.2 画图形象化问题1- 二叉树的镜像
- 20170928_二叉树的镜像
- 二叉树的镜像
- JAVA: 二叉树的镜像
- leetcode之二叉树的镜像
- 剑指offer--二叉树的镜像
- 剑指Offer题目1521:二叉树的镜像
- 【剑指offer】Q19:二叉树的镜像
- 二叉树的镜像
- 剑指Offer - 九度1521 - 二叉树的镜像
- 二叉树的镜像——19
- 剑指offer 矩形覆盖 树的子结构 二叉树的镜像 数组中重复的数字 第一个只出现一次的字符
- 二叉树镜像问题
- Invert Binary Tree 二叉树的镜像
- 剑指offer 二叉树的镜像
- 二叉树的镜像 【微软面试100题 第十五题】
- java 操作给定的二叉树,将其变换为源二叉树的镜像。
- 题目1521:二叉树的镜像
- 面试题19:二叉树的镜像