104. Maximum Depth of Binary Tree

来源:互联网 发布:c语言数组定义不加数字 编辑:程序博客网 时间:2024/05/20 23:26

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

class Solution {public:    int maxDepth(TreeNode* root)     {        if(!root)            return 0;        int HLtree=maxDepth(root->left);        int Hrtree=maxDepth(root->right);        return HLtree>Hrtree?HLtree+1:Hrtree+1;    }};
0 0
原创粉丝点击