Maximum Depth of Binary Tree
int _maxDepthH(TreeNode *root,int curDepth)
{
if(!root)
return curDepth;
curDepth++;
if(!root->left&&!root->right)
return curDepth;
int d1 = _maxDepthH(root->left,curDepth);
int d2 = _maxDepthH(root->right,curDepth);
return (d1>d2)?d1:d2;
}
int maxDepth(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
return _maxDepthH(root,0);
}
};
浙公网安备 33010602011771号