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.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its depth = 3.
/**
* 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 == NULL) return ; return max(maxDepth(root->left), maxDepth(root->right)) + ;
}
};
LeetCode 104. Maximum Depth of Binary Tree(二叉树深度)的更多相关文章
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- [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 long ...
- LeetCode 104. Maximum Depth of Binary Tree二叉树的最大深度 C++/Java
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 ☆(二叉树的最大深度)
描述 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the l ...
- Leetcode 104 Maximum Depth of Binary Tree 二叉树
计算二叉树的最大深度 我的方法是找出两个子树的长度中最长的那个,然后加1 class Solution { public: int maxDepth(TreeNode* root) { ; ,maxD ...
- LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- (二叉树 BFS DFS) 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 long ...
- 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 long ...
- 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 long ...
- 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 long ...
随机推荐
- Python 字符集
什么是字符? 1.在Python中,字符串中的内容都是字符. 2.什么是字符编码(encode)和字符集(charset)? 计算机只能识别数值,而字符不能识别,为了让计算机能处理字符,必须将字符和数 ...
- 将源码包制作成rpm包
Linux系统中一般安装软件有两种方法,源码安装和yum安装或者rpm包安装,由于光盘中的rpm包都是几年前制作成的,所以软件版本都很低,同时yum安装对软件的可定制性很低,所以为了使用最新的软件,一 ...
- 19、Python标准库: 日期和时间
一.time时间模块 import time 1 .时间戳 时间戳(timestamp):时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量. time_stamp = tim ...
- Virtual DOM的渲染机制--猜测
一个node的状态发生变化: 会对当前结点和子节点的数据全部进行更新: 然后进行dom比较: 比较完毕后一次性提交: 相对于以前的渲染方式: 每一个node的数据发生变化,都会产生一次渲染提交: 以上 ...
- UI的编程学本质
一.UI是数据的组织方式.展示及连接 UI模块--数据单元: 链接---数据单元间的联系: 相对链接-数据结构的树.链表: 绝对链接-大的模块级别的切换: 二.UI的IO学本质 屏幕.键盘 将信息输出 ...
- [Algorithm] 122. Best Time to Buy and Sell Stock II
Previous one: https://www.cnblogs.com/Answer1215/p/11974453.html Say you have an array for which the ...
- linux学习12 bash的常见特性及文本查看命令实战
一.回顾 1.FHS,命令及bash命令历史 a.FHS: /bin,/sbin,/lib,/lib64,/etc /home,/root /boot /media,/mnt /proc,/sys / ...
- Python爬虫selenium中get_cookies()和add_cookie()的用法
在用selenium爬取网页的时候,有时候需要登陆,这时候用selenium获取cookie和携带cookie是很方便的,获取cookie可以通过内置的函数get_cookies(),它得到的是一组c ...
- luoguP4173 残缺的字符串 FFT
luoguP4173 残缺的字符串 FFT 链接 luogu 思路 和昨天做的题几乎一样. 匹配等价于(其实我更喜欢fft从0开始) \(\sum\limits_{i=0}^{m-1}(S[i+j]- ...
- Ubuntu虚拟机下忘记密码的解决方法
由于好久没有用虚拟机里的ubuntu系统,导致忘记了密码.试了好多遍,密码都是错的,内心感到崩溃呀.选择只有两个:一个是重装系统,另一个是找回密码.自己不想重装系统只能找回密码了,在网上百度了好多,都 ...