maximum-depth-of-binary-tree
2015-07-02 16:39
267 查看
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int maxDepth(TreeNode *root) { if(!root) return 0; return max(maxDepth(root->left) + 1, maxDepth(root->right) + 1); } };
相关文章推荐
- poj 1163
- Kafka深度解析
- linux小操作-两个命令
- RedHat6配置yum
- 字符串转数组
- nextSibling和previousSibling
- WPF的菜单栏,工具栏的简单使用
- 解决iOS8通过SSH使用apt-get install安装时出现的问题
- 周期串问题
- Android Bitmap详细介绍
- Android高效加载大图、多图解决方案,有效避免程序OOM
- CentOS下安装实时检测网络带宽的小工具bmon
- CentOS下安装实时检测网络带宽的小工具bmon
- html span标签 不换行(有时span带中文时候是可以自动换行的)
- OEM无法登陆原因与ORACLE用户密码过期和锁定的解决办法(附上系统用户默认密码)
- EasyUI 中关于datetimebox赋值问题
- 《windows核心编程系列》四谈谈进程的建立和终止
- java学习笔记--如何用jar命令对java工程进行打包
- 提升Android应用开发性能的十大要点
- linux常用命令加实例大全