leetcode 104: Maximum Depth of Binary Tree
2015-08-12 13:06
405 查看
/** * 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) { return helper(root,1); } int helper(TreeNode* root,int depth) { if(!root) return depth-1; return max(helper(root->left,depth+1),helper(root->right,depth+1)); } };
相关文章推荐
- 总结------历时14个下午完成的安卓软件
- 8.12笔记 retrofit超时设置,studio 修改 Lint Error Checking
- 续上 编写Servlet查询数据库,列出员工信息列表
- java对于微信平台语音接收以及处理,语音下载以及arm格式转换MP3
- Mongodb 复制集Replica Set搭建与测试
- Hyper-V 中遇到错误 'vm' could not initialize
- 社交产品后端架构设计
- Quartz原理分析
- Windows 回调监控 <一>
- 通过若干个 Demo 进行讲解 Auto Layout
- Xcode配置SVN详细步骤
- 绘制一个简单的实现接口盘
- this compilation unit is not on the build of a java project
- va_list、va_start、va_end 宏用法小结
- jQuery(4)JQuery框架操作元素的属性与样式
- memset函数详解
- HDU5366 The mook jong (DP)
- ORACLE学习之scott用户的表结构sql
- IOS应用开发版本控制工具之Versions使用,iosversions
- leetcode 103: Binary Tree Zigzag Level Order Traversal