LeetCode OJ-- Maximum Depth of Binary Tree
https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/
求二叉树的最大深度
深度优先搜索
/**
* 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 ; int ans = ;
int now_depth;
deep(root,ans,);
return ans;
} void deep(TreeNode *root, int &max_depth, int now_depth)
{
if(root->left == NULL && root->right == NULL)
max_depth = max_depth < now_depth ? now_depth : max_depth; now_depth++; if(root->left)
deep(root->left,max_depth,now_depth);
if(root->right)
deep(root->right,max_depth,now_depth);
}
};
LeetCode OJ-- 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 OJ Minimum Depth of Binary Tree 递归求解
题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 111. Minimum Depth of Binary T ...
- 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流(Stream)、文件(File)和IO
Java.io包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io包中的流支持很多格式,比如:基本类型.对象.本地化字符集等等. 一个流可以理解为一个数据的序列 ...
- 动态规划:HDU1864-最大报销额(处理带小数的dp问题)
最大报销额 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Descriptio ...
- [BZOJ1187]神奇游乐园(插头DP)
Description 题意给定一个矩阵,每个格子有权值,在[-1000.1000]内,求一条回路使得回路经过权值和最大,每个格子最多经过一次 2≤n≤100,2≤m≤6 Code #include ...
- 使用HTTP协议访问网路
使用HTTP协议访问网路 一.使用HttpURLConnection //new一个URL对象 URL url = new URL("http://www.qq.com");//千 ...
- The DOM in JavaScript
DOM : Document Object Model D is for document : The DOM cant work without a document . When you c ...
- Proguard returned with error code 1. See console
满世界的bug. 微信支付,Windows的远程桌面. Android的 , Proguard returned with error code 1. See console解决办法" 真的 ...
- mysql插入、修改、删除
联合查询: union:合并.联合,将多次查询结果合并成一个结果 语法: 查询语句1: union[all] 查询语句2: union [all] ... 意义 1.将一条比较复杂的查询语句可拆分成多 ...
- wap html5播放器和直播开发小结
此文已由作者吴家联授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 去年年中的时候,借着产品改版的机会,将之前的h5播放器好好整理重构了一番.之前的h5播放器较为简陋,有几个大 ...
- Docker danriti/nginx-gunicorn-flask 使用
现成的镜像,已经配置好nginx-gunicorn-flask,可直接部署flask 项目 直接部署flask项目 安装镜像 如果默认源比较慢,可以换成163镜像源 http://hub-mirror ...
- ios开发学习笔记003-流程控制和类型转换
流程控制 顺序结构.选择结构.循环结构 1.顺序结构 程序默认是顺序执行的. 2.选择结构 if选择语句 第一种情况 if(条件)//条件成立执行下面语句 { //语句 } 第二种情况 if(条件)/ ...