LeetCode104: Maximum Depth of Binary Tree
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.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root) {
if (root == NULL)
{
return ;
}
int left = maxDepth(root->left);
int right = maxDepth(root->right);
if (left > right) {
left = left+;
return left;
}else
{
right = right;
return right;
}
}
LeetCode104: Maximum Depth of Binary Tree的更多相关文章
- LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
104. 二叉树的最大深度 104. 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 ...
随机推荐
- o4.数组指针和指针数组的区别
------- android培训.iOS培训.期待与您交流! ---------- 我们看一下数组指针和指针数组: 数组指针(也称行指针)定义 int (*p)[n];()优先级高,首先说明p是一个 ...
- python练习程序(c100经典例11)
题目: 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? a=1;b=1 print a,b, for i ...
- Java循环语句之 for
Java 的循环结构中除了 while 和 do...while 外,还有 for 循环,三种循环可以相互替换. 语法: 执行过程: <1>. 执行循环变量初始化部分,设置循环的初始状态, ...
- Informatica9.6.1在Linux Red Hat 5.8上安装遇到的有关问题整理_2
2. 产品安装过程提示Ping Domain Error 1)错误日志: Pinging domain... 8:19:22 AM ********************************** ...
- 嵌入式 VFS: Cannot open root device "mtdblock2" or unknown-block(2,0)
系统启动后,虽然nand驱动表现正常,但是最后挂载rootfs时候出错: Kernel command line: root=/dev/mtdblock2 rw init=/linuxrc conso ...
- .net发邮件 附件文件名乱码
.net发邮件 附件文件名乱码,可以下载以下补丁安装. https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.asp ...
- 【LeetCode 235】Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...
- 记录一次cefsharp1输入法在win7下异常解决定位
最近几天都被基于cefSharp封装的浏览器控件搞疯了!对于cefSharp基本满足当前所做项目的需求,但是有一个问题一直困扰我,那就是系统中偶尔会出现输入法不能转换到中文.而且这个问题似乎没有什么规 ...
- 从date中获取相应信息
创建测试用表: CREATE OR REPLACE VIEW v AS SELECT TO_DATE('2015-5-5 13:14:15', 'YYYY-MM-DD HH24:MI:SS') AS ...
- web.xml 配置介绍
这个不是原创,有点早了,具体从哪里来的已经记不得了.但是东西是实实在在的. 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<c ...