判断二叉树是否相等
/* * function TreeNode(x) { * this.val = x; * this.left = null; * this.right = null; * } */ /** * * @param p TreeNode类 * @param q TreeNode类 * @return bool布尔型 */ function isSameTree( p , q ) { // write code here if(!p || !q){ return p===q }else if(p.val!==q.val){ return false } return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right) } module.exports = { isSameTree : isSameTree };
树算法 文章被收录于专栏
树相关算法