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 f89a60e commit 8d34b59Copy full SHA for 8d34b59
MaximumDepthOfBinaryTree.java
@@ -0,0 +1,28 @@
1
+public class MaximumDepthOfBinaryTree {
2
+ public static void main(String[] args){
3
+ System.out.println("Maximum depth of the tree is : " + getDepth(getTree()));
4
+ }
5
+
6
+ public static class TreeNode {
7
+ int val;
8
+ TreeNode left;
9
+ TreeNode right;
10
+ TreeNode(int x) { val = x; }
11
12
13
+ private static int getDepth(TreeNode root) {
14
+ if(root == null) {
15
+ return 0;
16
17
+ return Integer.max(getDepth(root.left), getDepth(root.right)) + 1;
18
19
20
+ public static TreeNode getTree(){
21
+ TreeNode root = new TreeNode(10);
22
+ root.left = new TreeNode(5);
23
+ root.right = new TreeNode(15);
24
+ root.right.right = new TreeNode(20);
25
+ root.right.right.right = new TreeNode(23);
26
+ return root;
27
28
+}
0 commit comments