这道题预计是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;
}
};

leetcode第一刷_Maximum Depth of Binary Tree的更多相关文章

  1. leetcode第一刷_Minimum Depth of Binary Tree

    非常easy的题目.只是还是认为要说一下. 最小深度.非常快想到bfs,层序遍历嘛.本科的时候实在是没写过多少代码,一開始竟然想不到怎么保存一层的信息.后来想到能够压入一个特殊的对象,每次到达这个对象 ...

  2. 【一天一道LeetCode】#104. Maximum Depth of Binary Tree

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源:http ...

  3. 【LeetCode练习题】Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  4. 【LeetCode练习题】Maximum Depth of Binary Tree

    Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...

  5. LeetCode My Solution: Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Total Accepted: 24760 Total Submissions: 83665My Submissions Given a bi ...

  6. 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)

    Maximum Depth of Binary Tree  Given a binary tree, find its maximum depth. The maximum depth is the ...

  7. 【LeetCode】111. Minimum Depth of Binary Tree (2 solutions)

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  8. 【LeetCode OJ】Minimum Depth of Binary Tree

    Problem Link: http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ To find the minimum dept ...

  9. 【一天一道LeetCode】#111. Minimum Depth of Binary Tree

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

随机推荐

  1. zoj2760(最大流)

    传送门:How Many Shortest Path 题意:给出n个点,和n*n的矩阵表示有向图.a[i][j]为-1表示i到j没有路径:不为-1则表示i到j的路径长度.给出一个vs和vt,要求vs到 ...

  2. CC++刚開始学习的人编程教程(9) Windows8.1安装VS2013并捆绑QT与编程助手

    我们在Windows8.1安装VS2013并捆绑QT与编程助手须要下列文件. 2. 在虚拟机中开启Windows8.1 3.然后选择VS2013的安装镜像. 4.将镜像拷贝到虚拟机. 5.我们装载这个 ...

  3. 智能生活 “视”不可挡——首届TCL杯HTML5智能电视开发大赛等你来挑战

    http://www.csdn.net/article/2014-06-04/2820063-TCL-Smart-TV-Innovation-Competation

  4. vim配置(vimplus)

    vim配置(vimplus) vimplus vimplus是vim的超级配置安装程序 github地址:https://github.com/chxuan/vimplus.git,欢迎star和fo ...

  5. hdu1330(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1330 分析:经典问题,n 块相同的木板重叠,最多能够伸出桌面多远 对于n张卡片的最佳摆法,我们只需要在 ...

  6. 【LeetCode】Reorder List 解题报告

    Given a singly linked list L: L0→L1→-→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→- You must do th ...

  7. SE 2014年5月8日

    两企业接入到 Internet(A公司和B公司),企业内部的用户及服务器均能够访问到 Internet. 2. A公司规模较大,采用了接入层/汇聚层/核心层的划分模式,接入层划分了多vLan(如图), ...

  8. 最锋利的Visual Studio Web开发工具扩展:Web Essentials详解

    原文:最锋利的Visual Studio Web开发工具扩展:Web Essentials详解 Web Essentials是目前为止见过的最好用的VS扩展工具了,具体功能请待我一一道来. 首先,从E ...

  9. jeecg 3.5.2 新版本号4种首页风格 【经典风格,shortcut风格,ACE bootstrap风格,云桌面风格】

    [1]经典风格: [2]Shortcut风格: [3]ACE bootsrap风格: [4]云桌面风格: [5]自己定义图表 watermark/2/text/aHR0cDovL2Jsb2cuY3Nk ...

  10. 基于.net开发chrome核心浏览器【四】

    原文:基于.net开发chrome核心浏览器[四] 一: 上周去北京出差,给国家电网的项目做架构方案,每天都很晚睡,客户那边的副总也这样拼命工作. 累的不行了,直接导致第四篇文章没有按时发出来. 希望 ...