var isBalanced = function(root) {
function deep(root){//求深度
if(!root)return 0;
return Math.max(deep(root.left), deep(root.right)) + 1;
}
function dg(root){//递归
if(!root)return true;
return Math.abs(deep(root.left) - deep(root.right)) < 2 && dg(root.left) && dg(root.right);
}
return dg(root);
};
JS力扣刷题 110. 平衡二叉树
于 2022-04-27 09:55:50 首次发布