Update 0110.平衡二叉树.md

修改原有JS版本代码问题
This commit is contained in:
Anmizi
2022-02-06 23:33:11 +08:00
committed by GitHub
parent 08e226bb00
commit f1a3fbc788

View File

@ -614,8 +614,10 @@ var isBalanced = function(root) {
if(node === null) return 0; if(node === null) return 0;
// 3. 确定单层递归逻辑 // 3. 确定单层递归逻辑
let leftDepth = getDepth(node.left); //左子树高度 let leftDepth = getDepth(node.left); //左子树高度
let rightDepth = getDepth(node.right); //右子树高度 // 当判定左子树不为平衡二叉树时,即可直接返回-1
if(leftDepth === -1) return -1; if(leftDepth === -1) return -1;
let rightDepth = getDepth(node.right); //右子树高度
// 当判定右子树不为平衡二叉树时,即可直接返回-1
if(rightDepth === -1) return -1; if(rightDepth === -1) return -1;
if(Math.abs(leftDepth - rightDepth) > 1) { if(Math.abs(leftDepth - rightDepth) > 1) {
return -1; return -1;