leetcode 104 Maximum Depth of Binary Tree(DFS)
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;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int dfs(TreeNode *r){
if(r==NULL){
return ;
}
return max(dfs(r->left),dfs(r->right)) + ;
} int maxDepth(TreeNode* root) {
return dfs(root);
}
};
leetcode 104 Maximum Depth of Binary Tree(DFS)的更多相关文章
- 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二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- (二叉树 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 l ...
- 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 ...
随机推荐
- DML过程中记录错误日志
当你插入几百万数据时,由于有几条脏数据而导致插入失败,是不是很恼火.10g R2之后有个新功能.将插入过程中失败的记录插入到还有一张表中. SQL> drop table test purge; ...
- 各个DDR对比
一.容量和封装相关 (1)逻辑Bank数量增加 DDR2 SDRAM中有4Bank和8Bank的设计,而DDR3起始的逻辑Bank是8个,另外还为未来的16个逻辑Bank做好了准备. (2)封装(Pa ...
- java Map 实现类的对比
java为数据结构中的映射定义了一个接口 java.util.Map ,他有四个实现类
- 深入理解Java 8 Lambda
- 转载:blog1, blog2 以上两篇博客是对lambda表达式的深入理解,用于后续加深理解. 如下先从零开始理解lambda, 1. 接触lambda表达式是从python,javascrip ...
- pm2 服务崩溃 Error: bind EADDRINUSE
pm2 服务崩溃 Error: bind EADDRINUSE 发布于 1 年前 作者 zhujun24 2444 次浏览 来自 问答 Error: bind EADDRINUSE 0.0.0 ...
- html 锚点定位
在html中设置锚点定位我知道的有几种方法.在此和大家分享一下: 1.使用id定位: <a href="#1F" name="1F">锚点1< ...
- doT.js具体使用介绍
官网: http://olado.github.iodoT.js具体使用介绍 用法: {{= }} for interpolation {{ }} for evaluation {{~ }} for ...
- BeeFramework 系列二 UISignal篇下
本文转载至 http://www.apkbus.com/android-126129-1-1.html qihoo2 该用户从未签到 156 主题 156 帖子 1826 积分 Android ...
- GS与网络打交道
与网络打交道 在GS,GC,Share都与网络打交道,但还是GC最多 GC打交道过程 send_stat BaseChannel::SendCmdTry() { if (!m_queCmd.size( ...
- 九度OJ 1083:特殊乘法 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4114 解决:2809 题目描述: 写个算法,对2个小于1000000000的输入,求结果. 特殊乘法举例:123 * 45 = 1*4 + ...