We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e4fdd89 commit 3e0daa6Copy full SHA for 3e0daa6
Binary Tree/MaximumDepthOfTree.java
@@ -0,0 +1,32 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * public class TreeNode {
4
+ * int val;
5
+ * TreeNode left;
6
+ * TreeNode right;
7
+ * TreeNode() {}
8
+ * TreeNode(int val) { this.val = val; }
9
+ * TreeNode(int val, TreeNode left, TreeNode right) {
10
+ * this.val = val;
11
+ * this.left = left;
12
+ * this.right = right;
13
+ * }
14
15
+ */
16
+
17
+import java.util.*;
18
+class MaximumDepthOfTree {
19
+ public int maxDepth(TreeNode root) {
20
+ return postorder(root);
21
+ }
22
23
+ public static int postorder(TreeNode root){
24
+ if(root == null){
25
+ return 0;
26
27
28
+ int leftDepth = postorder(root.left);
29
+ int rightDepth = postorder(root.right);
30
+ return 1+Math.max(leftDepth, rightDepth);
31
32
+}
0 commit comments