mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-14 01:16:07 +08:00
Merge pull request #493 from JayH2018/patch-2
source coding is a little complex
This commit is contained in:
@ -37,14 +37,10 @@ public class LevelOrderTraversal
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
/* compute height of each subtree */
|
||||
int lheight = height(root.left);
|
||||
int rheight = height(root.right);
|
||||
|
||||
/* use the larger one */
|
||||
if (lheight > rheight)
|
||||
return(lheight+1);
|
||||
else return(rheight+1);
|
||||
/**
|
||||
* Return the height of larger subtree
|
||||
*/
|
||||
return Math.max(height(root.left),height(root.right)) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user