19、二叉树的镜像
2017-07-30 17:03
232 查看
越来越喜欢递归了!
/**
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;
//if(root.left == null && root.right == null) return;
if(root.left != null) Mirror(root.left);
if(root.right != null) Mirror(root.right);
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
}
}
/**
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;
//if(root.left == null && root.right == null) return;
if(root.left != null) Mirror(root.left);
if(root.right != null) Mirror(root.right);
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
}
}
相关文章推荐
- 剑指offer 19. 二叉树的镜像
- 剑指offer面试题19二叉树的镜像和二叉树的前中后遍历递归和非递归算法
- 面试题19:二叉树的镜像
- 面试题19 二叉树的镜像
- 剑指Offer 19 : 二叉树镜像
- 剑指offer面试题[19]-二叉树的镜像
- 面试题19:二叉树的镜像
- 剑指offer阅读笔记 之面试题19 实现二叉树的镜像 之 又复习一遍二叉树
- 面试题19—二叉树的镜像
- 剑指Offer 19 二叉树的镜像
- 面试题19:二叉树的镜像
- 剑指offer-4-面试19:二叉树的镜像
- 剑指Offer之面试题19:二叉树的镜像
- 19_二叉树的镜像
- 【面试题19】二叉树的镜像
- 剑指Offer系列-面试题19:二叉树的镜像
- [剑指offer][面试题19]二叉树的镜像
- 剑指offer面试题19 二叉树的镜像
- 剑指offer19:二叉树的镜像
- P125、面试题19:二叉树的镜像