Skip to content

Commit 5a28ee0

Browse files
committed
Runtime: 1 ms (Top 65.91%) | Memory: 42.9 MB (Top 74.91%)
1 parent cbae679 commit 5a28ee0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scripts/algorithms/D/Diameter of Binary Tree/Diameter of Binary Tree.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 1 ms (Top 65.91%) | Memory: 42.9 MB (Top 74.91%)
12
class Solution {
23
// Declare Global Variable ans to 0
34
int ans = 0;
@@ -8,14 +9,13 @@ public int dfs(TreeNode root) {
89
int lh = dfs(root.left);
910
// recursive call for right height
1011
int rh = dfs(root.right);
11-
12+
1213
// update ans
1314
ans = Math.max(ans, lh + rh);
14-
15+
1516
// return max value
1617
return Math.max(lh, rh) + 1;
1718
}
18-
1919

2020
// Diameter of Binary Tree Function
2121
public int diameterOfBinaryTree(TreeNode root) {
@@ -36,4 +36,4 @@ public int diameterOfBinaryTree(TreeNode root) {
3636
/*
3737
Time - O(n)
3838
Space - O(n)
39-
*/
39+
*/

0 commit comments

Comments
 (0)