【LeetCode】(104)Maximum Depth of Binary Tree(Easy)
2015-08-20 15:52
316 查看
题目
Maximum Depth of Binary Tree
Total Accepted: 79538 TotalSubmissions: 176206My Submissions
Question
Solution
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 a binary tree node. * 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==nullptr) { return 0; } return max(maxDepth(root->right),maxDepth(root->left))+1; } };
相关文章推荐
- Android 自定义View解决引导,操作指导等操作,你还在用ViewPager么?
- 《祝你一路顺风》-吴奇隆
- bind()函数的作用
- iOS拨打电话的3种方式(转载)
- date iso 8610
- INSERT INTO .. ON DUPLICATE KEY更新多行记录
- 对这次8.1-8.20暑假信息学集训总结
- mongodb基础结构
- android 点滴——JSON
- 机房收费系统优化之MSHFlexGrid控件的使用
- JavaScript(二)-10-(常见对象-Date-基本方法)
- 一些自己总是忘记的内容
- Xamarin.Android 如何使用Assets目录下的文件
- js很好的教材
- arcengine发布webservice编辑sde
- Hibernate4注解方法
- Ubuntu 下 Ionic 环境配置
- CentOS7安装MySql,防火墙关闭,远程访问
- 一个透明且没有title的activity
- 纯手工gcc 编译android native Cpp代码