[LeetCode] Maximum Depth of Binary Tree
2015-09-29 23:41
453 查看
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.
递推算法 4ms AC
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
递推算法 4ms AC
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int maxDepth(struct TreeNode* root) { if(root!=NULL) { int leftlength=maxDepth(root->left); int rightlength=maxDepth(root->right); return leftlength>rightlength? leftlength+1:rightlength+1; } else return 0; }
相关文章推荐
- Android实现炫酷的星空变幻效果
- 如何在ROM中集成可卸载的APK
- Android适配器进阶之二(分类适配器)
- 第二次博客作业
- AndroidUI 视图动画-旋转动画效果 (RotateAnimation)
- 周记 - 9.29
- Dom4j对XML文档的增删改查操作
- <AE之路>视频制式基础
- AndroidUI 视图动画-旋转动画效果 (RotateAnimation)
- JAVA设计模式之备忘录模式
- "不能在 DropDownList 中选择多个项。"其解决办法及补充
- 网络配置管理之ip、ss、配置文件、网卡命名规则、nmcli
- 个人博客作业Week2
- android 自定义控件 -- 画板
- PHP脚本的错误处理方式(PHP实战手册读书笔记)
- Scipy教程 - 距离计算库scipy.spatial.distance
- Scipy教程 - 距离计算库scipy.spatial.distance
- 当输入为多个,输出为多个时(多线程)
- 关于EditPlus3 取消备份后再重新打开 备份设置还原到默认状态的问题
- 【笔试面试】数组相关问题