Skip to content

Commit 1dff090

Browse files
committed
Runtime: 19 ms (Top 46.08%) | Memory: 20.1 MB (Top 92.89%)
1 parent ac42d39 commit 1dff090

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
// Runtime: 19 ms (Top 46.08%) | Memory: 20.1 MB (Top 92.89%)
12
class Solution {
2-
3+
34
int solve(TreeNode* root, int &dia) {
45
if(root == NULL) return 0;
56
int lh = solve(root->left, dia);
67
int rh = solve(root->right, dia);
78
dia=max(dia,lh+rh);
89
return max(lh,rh)+1;
910
}
10-
11+
1112
public:
1213
int diameterOfBinaryTree(TreeNode* root) {
1314
int dia=0;
1415
solve(root, dia);
1516
return dia;
1617
}
17-
};
18+
};

0 commit comments

Comments
 (0)