[leetcode] 8. 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 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 aspros = maxDepth(root->left);
int defteros = maxDepth(root->right);
return 1 + (aspros>defteros ? aspros : defteros);
}
}
};
非常简单,重复复用。
[leetcode] 8. Maximum Depth of Binary Tree的更多相关文章
- 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 ...
- 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 C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- [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 ...
- (二叉树 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 题解]: 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
Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...
- leetcode 104 Maximum Depth of Binary Tree ----- java
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Java [Leetcode 104]Maximum Depth of Binary Tree
题目描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...
随机推荐
- 关于android 动态设置view 样式 问题(默认style)
解决方案一: Button btn=new Button(new ContextThemeWrapper(mContext,R.style.service_text_dialog_style),nul ...
- NGINX 添加MP4、FLV视频支持模块
由于公司网站需要放置视频,但是默认的服务器环境是没有编译这个支持的模块,视频文件只能缓冲完了在播放,非常麻烦. 之前呢也安装了一个nginx_mod_h264_streaming来支持,效果很不错 ...
- Log4j(1)--hellloworld
创建项目: 使用的是log4j-1.2.17.jar: log4j.properties: log4j.rootLogger=DEBUG, Console ,File #Console log4j.a ...
- Bootstrap-Plugin:弹出框(Popover)插件
ylbtech-Bootstrap-Plugin:弹出框(Popover)插件 1.返回顶部 1. Bootstrap 弹出框(Popover)插件 弹出框(Popover)与工具提示(Tooltip ...
- 6.9-JDBC
一.JDBC 步骤: 1.加载驱动 2.创建连接 3.创建Statement或PreparedStatement 4.遍历结果集 5.释放资源 二.PrepareStatement sql注入: Pr ...
- Pthreads 读写锁
▶ 使用读写锁来限制同一数据多线程读写.若任何线程拥有读锁,则其他任何请求写锁的线程将阻塞在其写锁函数的调用上:若任何线程拥有写锁,则其他任何请求读锁和写锁的线程将阻塞在其对应的锁函数上,相当于将读与 ...
- 在浏览器输入URL后发生了什么?
摘录部分一:https://www.cnblogs.com/kongxy/p/4615226.html 从输入URL到浏览器显示页面发生了什么 当在浏览器地址栏输入网址,如:www.baidu.com ...
- 问题记录,StartCoroutine(“str")问题
StartCoroutine参数为函数字符串名,运行时出错,错误是:无法启动协程函数. 调用格式如下: gameManager.StartCoroutine(LuaOnLevelwasloaded() ...
- 回文O(N)算法
[回文O(N)算法] 利用回文的对称性质,可以设计出O(N)的算法. 参考:http://blog.csdn.net/ggggiqnypgjg/article/details/6645824
- 44. Wildcard Matching (String; DP, Back-Track)
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...