二叉树的镜像
二叉树的镜像
http://www.nowcoder.com/questionTerminal/564f4c26aa584921bc75623e48ca3011
思路分析:
将二叉树的左右子树进行互换,然后再将左右子树进行递归处理 返回出口:root == null return
/**
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 tmpNode = root.left;
root.left = root.right;
root.right = tmpNode;
Mirror(root.left);
Mirror(root.right);
}
} 

上海得物信息集团有限公司公司福利 1166人发布