mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0110.平衡二叉树.md
修改原有JS版本代码问题
This commit is contained in:
@ -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;
|
||||||
|
Reference in New Issue
Block a user