We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cbae679 commit 5a28ee0Copy full SHA for 5a28ee0
scripts/algorithms/D/Diameter of Binary Tree/Diameter of Binary Tree.java
@@ -1,3 +1,4 @@
1
+// Runtime: 1 ms (Top 65.91%) | Memory: 42.9 MB (Top 74.91%)
2
class Solution {
3
// Declare Global Variable ans to 0
4
int ans = 0;
@@ -8,14 +9,13 @@ public int dfs(TreeNode root) {
8
9
int lh = dfs(root.left);
10
// recursive call for right height
11
int rh = dfs(root.right);
-
12
+
13
// update ans
14
ans = Math.max(ans, lh + rh);
15
16
// return max value
17
return Math.max(lh, rh) + 1;
18
}
19
20
// Diameter of Binary Tree Function
21
public int diameterOfBinaryTree(TreeNode root) {
@@ -36,4 +36,4 @@ public int diameterOfBinaryTree(TreeNode root) {
36
/*
37
Time - O(n)
38
Space - O(n)
39
-*/
+*/
0 commit comments