BinaryTreeNode.js height() gives one less than tree's height.

The height of the tree is the number of edges in the tree from the root to the deepest node. 

height right now gives one less than the total number of the edges, small tweek made will fix it.
This commit is contained in:
Gyaneshwar Sunkara 2023-09-08 00:53:51 -04:00 committed by GitHub
parent 76617fa83a
commit 6800c9aac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,7 @@ export default class BinaryTreeNode {
return 0;
}
return this.left.height + 1;
return this.left.height;
}
/**
@ -37,14 +37,14 @@ export default class BinaryTreeNode {
return 0;
}
return this.right.height + 1;
return this.right.height;
}
/**
* @return {number}
*/
get height() {
return Math.max(this.leftHeight, this.rightHeight);
return Math.max(this.leftHeight, this.rightHeight) + 1;
}
/**