mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +08:00
Fix binary tree node.
This commit is contained in:
parent
b24763e249
commit
d19149de8e
@ -6,15 +6,24 @@ export default class BinaryTreeNode {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
get height() {
|
get leftHeight() {
|
||||||
if (!this.left && !this.right) {
|
if (!this.left) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const leftHeight = this.left ? this.left.height : 0;
|
return this.left.height + 1;
|
||||||
const rightHeight = this.right ? this.right.height : 0;
|
}
|
||||||
|
|
||||||
return Math.max(leftHeight, rightHeight) + 1;
|
get rightHeight() {
|
||||||
|
if (!this.right) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.right.height + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
get height() {
|
||||||
|
return Math.max(this.leftHeight, this.rightHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLeft(node) {
|
setLeft(node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user