Compare commits

...

2 Commits

Author SHA1 Message Date
Gyaneshwar Sunkara
ee6299dad1
Merge 6800c9aac9 into 2c67b48c21 2024-03-09 16:08:15 -07:00
Gyaneshwar Sunkara
6800c9aac9
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.
2023-09-08 00:53:51 -04:00

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;
}
/**