We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ac42d39 commit 1dff090Copy full SHA for 1dff090
scripts/algorithms/D/Diameter of Binary Tree/Diameter of Binary Tree.cpp
@@ -1,17 +1,18 @@
1
+// Runtime: 19 ms (Top 46.08%) | Memory: 20.1 MB (Top 92.89%)
2
class Solution {
-
3
+
4
int solve(TreeNode* root, int &dia) {
5
if(root == NULL) return 0;
6
int lh = solve(root->left, dia);
7
int rh = solve(root->right, dia);
8
dia=max(dia,lh+rh);
9
return max(lh,rh)+1;
10
}
11
12
public:
13
int diameterOfBinaryTree(TreeNode* root) {
14
int dia=0;
15
solve(root, dia);
16
return dia;
17
-};
18
+};
0 commit comments