leetcode第一刷_Maximum Depth of Binary Tree

这道题预计是ac率最高的一道了。你当然能够用层序遍历,我佩服你的耐心和勇气。由于看到别人的三行代码,会不会流眼泪呢。。

class Solution {
public:
    int maxDepth(TreeNode *root) {
        if(root == NULL)    return 0;
        if(!root->left&&!root->right)   return 1;
        return max(maxDepth(root->left), maxDepth(root->right))+1;
    }
};


posted @ 2016-01-06 20:45  mengfanrong  阅读(179)  评论(0)    收藏  举报
众安尊享e升2025版 - 底部横幅广告
尊享e升 2025版
🚀 全新升级
百万医疗险全面升级 守护健康人生
✓ 一般医疗300万
✓ 重疾600万
✓ 6年保证续保
✓ 1万免赔额
600万
最高保障
首月特惠价
低至1元起
🛡️ 立即投保