Leetcode 104 Maximum Depth of Binary Tree 二叉树

计算二叉树的最大深度

我的方法是找出两个子树的长度中最长的那个,然后加1

1 class Solution {
2 public:
3     int maxDepth(TreeNode* root) {
4         if(!root) return 0;
5         else return max(maxDepth(root->left)+1,maxDepth(root->right)+1);
6     }
7 };

 

posted @ 2016-01-16 20:07  Breeze0806  阅读(115)  评论(0编辑  收藏  举报