Maximum Depth of Binary Tree
2015-11-02 09:17
197 查看
题目:
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 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->left), maxDepth(root->right)) + 1; } };
相关文章推荐
- css书写规范整理
- Android AndroidManifest 清单文件以及权限详解
- chrome浏览器控制台
- 【NOIP2011】选择客栈 乱搞
- js完美身份证验证
- jQuery 在Table中选择input之类的东西注意事项
- 项目考核维度
- dataGridView设置指定列不能修改
- QT基于UDP通信的多线程编程问题
- unaryPred函数对象,函数适配器(一)
- 数据库设计原则
- [转]优化数据库大幅度提高Oracle的性能
- Spring MVC全局异常处理与拦截器校检
- Xcode7免证书真机调试
- 如何对付网络爬虫 - JavaEye和网络爬虫斗争之路
- linux系统部署项目的日常命令
- jQuery 对象与Dom 对象互转
- 全球网络安全专业实力最强十所大学
- 查看linux服务器的cpu信息
- JavaScript Length 属性的总结