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 9bfc445 commit 4ad8df0Copy full SHA for 4ad8df0
Trees/BinaryTree.java
@@ -200,6 +200,21 @@ private void levelOrderTraversal() {
200
}
201
202
203
+ private int heightOfBinaryTree(TreeNode root) {
204
+ int leftHeight = 0;
205
+ int rightHeight = 0;
206
+
207
+ if(root.left != null) {
208
+ leftHeight = 1 + heightOfBinaryTree(root.left);
209
+ }
210
211
+ if(root.right != null) {
212
+ rightHeight = 1 + heightOfBinaryTree(root.right);
213
214
215
+ return Math.max(leftHeight, rightHeight);
216
217
218
public static void main(String[] args) {
219
220
BinaryTree binaryTree = new BinaryTree();
0 commit comments