func-package

函数库, 面向复杂业务场景的 js 类库

对称的二叉树

题目描述

请实现一个函数,用来判断一颗二叉树是不是对称的。注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。

function isSymmetrical(pRoot)
{
// write code here
if(pRoot==null){
return true
}
return judge(pRoot.left,pRoot.right)
}
function judge(left,right){
if(left==null){return right==null}
if(right==null){return false}
if(left.val!=right.val){return false}
return judge(left.left,right.right)&&judge(left.right,right.left)
}