LeetCodeOJ. Maximum Depth of Binary Tree
见问题: https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/
主题概述
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解题思路
经典数据结构作业题, 当然也是经典的面试题.
源码
/**
* Definition for binary tree
* 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 == NULL ) {
return 0;
} else {
int leftDepth = maxDepth(root->left) + 1;
int rightDepth = maxDepth(root->right) + 1; return ( leftDepth > rightDepth ? leftDepth : rightDepth );
}
}
};
LeetCodeOJ. Maximum Depth of Binary Tree的更多相关文章
- [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...
- LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...
- Leetcode | Minimum/Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- 104. Maximum Depth of Binary Tree(C++)
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
随机推荐
- CentOS配置smaba与Windows共享文件
操作环境:CentOS 6.5 64bit Linux与Linux间通过什么共享文件呢--NFS,Windows与Windows之间呢--共享文件功能就OK了,那Windows与Linux之间呢? 这 ...
- Web API Test Client 1.2.0
使用方法 1 安装 matthewcv.WebApiTestClient 到你的Web API 项目 PM> Install-Package matthewcv.WebApiTestClient ...
- C#的WebBrowser控制浏览
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 使用Simple DNS plus 构建自己的DNS
1.下载并安装Simple DNS plus 2.界面例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2tfYm9zcw==/font/5a6L ...
- 11gRAC CHM 管理
Cluster Health Monitor(缩写CHM)是Oracle提供的工具,自己主动的资源来收集操作系统(CPU.内存.SWAP.过程.I/O与网络)用法. CHM数据被收集每秒一次,11.2 ...
- B/S VS C/S
从软件project的学习到如今的机房合作,我们一直在学习C/S,进入牛腩才正式进入了对B/S的了解,确切点牛腩则是对此的一个过渡,起到了承上启下的作用!看牛腩,事实上最大的感受就是他不止要设计到页面 ...
- android:ViewPager动画摘要
动画节目: 我们可以用ViewPager的setPageTransformer办法,至ViewPager动画.示及效果: 1.CubeInTransformer 2.CubeOutTransforme ...
- hdu 4945 2048 (dp+组合的数目)
2048 Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- POJ 2226 Muddy Fields(最小顶点覆盖)
POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...
- Sphinx/Coreseek 4.1 跑 buildconf.sh 一个错误,无法生成configure档
安装前 coorseek 什么时候,遇到一些错误.该官方网站无法看到的解决方案,终于 google 在大牛的博客评论区找到一个解决方案.突然跑到他的膝盖介绍~~ 这里整理是为了方便一些人发现,墙毕竟让 ...