【LeetCode】104 - 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.
Solution:
/**
* Definition for a binary tree node.
* 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)
return ;
else if(root->left && !root->right)
return +maxDepth(root->left);
else if(!root->left && root->right)
return +maxDepth(root->right);
else
return +max(maxDepth(root->right),maxDepth(root->left));
}
};
【LeetCode】104 - Maximum Depth of Binary Tree的更多相关文章
- 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the ...
- 【LeetCode】104. Maximum Depth of Binary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:BFS 方法二:DFS 参考资料 日期 题目 ...
- 【一天一道LeetCode】#104. Maximum Depth of Binary Tree
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源:http ...
- 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度
求二叉树的最大深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...
- 【LeetCode】662. Maximum Width of Binary Tree 解题报告(Python)
[LeetCode]662. Maximum Width of Binary Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.co ...
- 【LeetCode】111. Minimum Depth of Binary Tree (2 solutions)
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode OJ 104. 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:104 Maximum Depth of Binary Tree(easy)
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- 【LeetCode】111. Minimum Depth of Binary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 [LeetCode] 题目地址 ...
随机推荐
- java string,需要进行首字母大写改写
java string,需要进行首字母大写改写,网上大家的思路基本一致,就是将首字母截取,转化成大写然后再串上后面的,类似如下代码 //首字母大写 public static String c ...
- NET在SQL Server中的图片存取技术
本文总结如何在.Net WinForm和.Net WebForm(asp.net)中将图片存入SQL Server中并读取显示的方法 .1.使用asp.net将图片上传并存入SQL Server中,然 ...
- 由反汇编C程序来理解计算机是如何工作的
C语言代码 int g(int x) { return x + 109; } int f(int x) { return g(x); } int main() { return f(122) + 3; ...
- MTK
1.mt_boot_init->boot_linux_from_storage->boot_linux->boot_linux_fdt
- 同步synchronized用法
今天在高人的指导下,对同步synchronized用法有了更高一层的理解,非常感谢他的无私奉献.在此把代码贴出来方便日后查阅. publicclass SfServlet { privatestati ...
- CSS控制超链接
一.伪类 CSS控制元素的某种状态---偽类(用于向某些选择器添加特殊的效果) 偽类的语法:元素标签 偽类名称{属性:属性值;} 二.超链接 a:link:未访问的链接 ...
- linux字符驱动程序结构
linux内核为字符设备的驱动程序设计,提供了一些数据结构,和函数,供开发人员调用,将设备驱动程序注册到内核去.现代操作系统几乎都不直接和硬件通信,而是通过定义的接口,是硬件厂商自己来开发符合标准某个 ...
- android漂亮的对话框项目sweet-alert-dialog
漂亮的对话框 sweet-alert-dialog 项目地址: https://github.com/pedant/sweet-alert-dialog android原生的dialog太生硬了, ...
- [转] 判断html页是否滚动停止
原文链接:http://www.phpernote.com/javascript-function/754.html 最近有个项目中遇到这样一个问题: 有一个用于展示数据的带滚动条的DIV块,业务需求 ...
- (七)7.2 应用机器学习方法的技巧,准确率,召回率与 F值
建立模型 当使用机器学习的方法来解决问题时,比如垃圾邮件分类等,一般的步骤是这样的: 1)从一个简单的算法入手这样可以很快的实现这个算法,并且可以在交叉验证集上进行测试: 2)画学习曲线以决定是否更多 ...