mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
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:
parent
76617fa83a
commit
6800c9aac9
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user