题解 | #对称的二叉树#
对称的二叉树
http://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
/* function TreeNode(x) {
this.val = x;
this.left = null;
this.right = null;
} */
function isSymmetrical(pRoot)
{
// write code here
if(pRoot === null){
return true
}
return isequel(pRoot.left,pRoot.right)
}
function isequel(left,right){
if(left == null && right == null){
return true
}
if(left === null || right === null ){
return false
}
if(left.val !== right.val){
return false
}
return isequel(left.left,right.right) && isequel(left.right,right.left)
}
module.exports = {
isSymmetrical : isSymmetrical
};