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);
    }
};

  

posted @ 2013-05-29 17:55  summer_zhou  阅读(117)  评论(0编辑  收藏  举报