We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b24763e commit d19149dCopy full SHA for d19149d
src/data-structures/tree/BinaryTreeNode.js
@@ -6,15 +6,24 @@ export default class BinaryTreeNode {
6
this.value = value;
7
}
8
9
- get height() {
10
- if (!this.left && !this.right) {
+ get leftHeight() {
+ if (!this.left) {
11
+ return 0;
12
+ }
13
+
14
+ return this.left.height + 1;
15
16
17
+ get rightHeight() {
18
+ if (!this.right) {
19
return 0;
20
21
- const leftHeight = this.left ? this.left.height : 0;
- const rightHeight = this.right ? this.right.height : 0;
22
+ return this.right.height + 1;
23
24
- return Math.max(leftHeight, rightHeight) + 1;
25
+ get height() {
26
+ return Math.max(this.leftHeight, this.rightHeight);
27
28
29
setLeft(node) {
0 commit comments