Maximum Depth of Binary Tree
来源:互联网 发布:电脑版淘宝客服打不开 编辑:程序博客网 时间:2024/06/05 12:40
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.
题意:求二叉树的最大深度(根节点到叶节点的节点数)
对于树,一般用递归比较简单,代码明确,先试试递归吧!
int maxDepth(TreeNode *root) {int dep = 0;if(root != NULL){int leftDep = maxDepth(root->left);int rightDep = maxDepth(root->right);dep = leftDep > rightDep ? leftDep : rightDep;dep ++;}return dep;}
0 0
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Broadcast(2)
- MVC架构
- Java 串行化技术_Serializable
- 详细讲解C++ 类的继承
- java学习第六天
- Maximum Depth of Binary Tree
- 从普通交换机的转发流程看Openflow交换机
- [面试算法]有一无符号整型数组,大小为10, 初始的数值随机,但在[0, 99]之间。请用C语言写一个过滤程序,令数组内的数据互不相等。
- linux IPC-消息队列 的内核限制
- MP3播放器1.0版本
- OJ_1135
- mysql系列:数据库优化
- 调用操作符和函数对象
- linux进程间通信4——消息队列