Maximum Depth of Binary Tree
来源:互联网 发布:jquery.alert.js 编辑:程序博客网 时间:2024/05/08 10:09
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.
点击打开原题链接
这个题剑指offer里也有,简单的递归即可,代码很清晰:
class Solution {public:int maxDepth(TreeNode *root) {if (root == NULL){return 0;}else{int a = maxDepth(root->left) + 1;int b = maxDepth(root->right) + 1;if (a > b){return a;} else{return b;}}}private://static int depth;};
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
- c++怎么计算代码运行时间到超精确毫秒级别
- sip命令与音视频rtp通话完整流程分析
- K-近邻算法python实现
- Leetcode Triangle
- 共享内存映射之mmap()函数详解
- Maximum Depth of Binary Tree
- mybatis好文收藏
- Leetcode Remove Duplicates from Sorted Array
- 2023 求平均成绩
- 一个关于时间的故事(通过历史分析解决程序问题)
- maven新建web项目时报错
- Ios左右菜单PPRevealSideviewController使用的一些心得
- 任正非对研究部门的方向指导
- ubuntu下OPTIMUS显卡CUDA编程bumblebee解决方法