1. 操作给定的二叉树,将其变换为源二叉树的镜像。
function Mirror(root)
{
// write code here
if(!root) return null;
var left,right;
if(root.right){
left=Mirror(root.right);
}
if(root.left){
right=Mirror(root.left);
}
root.left=left;
root.right=right;
return root;
}
2. 输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。
function TreeDepth(pRoot)
{
// 如果没有节点 则返回0
if(!pRoot) return 0
// 判断左子树/右子树的深度
var left=TreeDepth(pRoot.left);
var right=TreeDepth(pRoot.right);
return 1+Math.max(left,right)
}

511

被折叠的 条评论
为什么被折叠?



