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 ff92056 commit 28dedddCopy full SHA for 28deddd
DataStructures/Trees/LevelOrderTraversal.java
@@ -37,14 +37,10 @@ int height(Node root)
37
return 0;
38
else
39
{
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);
+ /**
+ * return the larger one;
+ */
+ return Math.max(height(root.left),height(root.right)) + 1;
48
}
49
50
@@ -75,4 +71,4 @@ public static void main(String args[])
75
71
System.out.println("Level order traversal of binary tree is ");
76
72
tree.printLevelOrder();
77
73
78
-}
74
+}
0 commit comments