Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- int maxi;
- int Depth(TreeNode* root) {
- if (root==nullptr)
- return 0;
- auto dL = Depth(root->left);
- auto dR = Depth(root->right);
- if (maxi < dL+dR+1)
- maxi=dL+dR+1;
- return std::max(dL,dR)+1;
- }
- public:
- int diameterOfBinaryTree(TreeNode* root) {
- maxi=0;
- if (root==nullptr)
- return 0;
- return std::max(Depth(root),maxi)-1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement