class Solution {
public:
int res = 0;
int depth(TreeNode* root){
if(!root) return 0;
int left = depth(root->left);
int right = depth(root->right);
res = max(res, left + right + 1);
return max(left, right) + 1;
}
int diameterOfBinaryTree(TreeNode* root) {
if(!root) return 0;
depth(root);
return res - 1;
}
};
05-30