Skip to content

Commit 826e7b5

Browse files
authored
Merge pull request TheAlgorithms#493 from JayH2018/patch-2
source coding is a little complex
2 parents ff92056 + 2dc86b6 commit 826e7b5

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

DataStructures/Trees/LevelOrderTraversal.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@ int height(Node root)
3737
return 0;
3838
else
3939
{
40-
/* compute height of each subtree */
41-
int lheight = height(root.left);
42-
int rheight = height(root.right);
43-
44-
/* use the larger one */
45-
if (lheight > rheight)
46-
return(lheight+1);
47-
else return(rheight+1);
40+
/**
41+
* Return the height of larger subtree
42+
*/
43+
return Math.max(height(root.left),height(root.right)) + 1;
4844
}
4945
}
5046

@@ -75,4 +71,4 @@ public static void main(String args[])
7571
System.out.println("Level order traversal of binary tree is ");
7672
tree.printLevelOrder();
7773
}
78-
}
74+
}

0 commit comments

Comments
 (0)