Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d19149d

Browse files
committedApr 5, 2018
Fix binary tree node.
1 parent b24763e commit d19149d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

‎src/data-structures/tree/BinaryTreeNode.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@ export default class BinaryTreeNode {
66
this.value = value;
77
}
88

9-
get height() {
10-
if (!this.left && !this.right) {
9+
get leftHeight() {
10+
if (!this.left) {
11+
return 0;
12+
}
13+
14+
return this.left.height + 1;
15+
}
16+
17+
get rightHeight() {
18+
if (!this.right) {
1119
return 0;
1220
}
1321

14-
const leftHeight = this.left ? this.left.height : 0;
15-
const rightHeight = this.right ? this.right.height : 0;
22+
return this.right.height + 1;
23+
}
1624

17-
return Math.max(leftHeight, rightHeight) + 1;
25+
get height() {
26+
return Math.max(this.leftHeight, this.rightHeight);
1827
}
1928

2029
setLeft(node) {

0 commit comments

Comments
 (0)
Please sign in to comment.