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)的更多相关文章

  1. LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告

    104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...

  2. leetcode 104 Maximum Depth of Binary Tree二叉树求深度

    Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...

  3. (二叉树 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 ...

  4. [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 ...

  5. 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 ...

  6. [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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 在MyEclipse上部署Tomcatserver

    我在前面的博客中介绍了在Windows下安装Tomcatserver.这篇博客将介绍在MyEclipse上部署Tomcatserver 第一步:启动MyEclipse 第二步:选项Window-> ...

  2. (四)DOM对象和jQuery对象

    学习jQuery,需要搞清楚DOM对象和jQuery对象的关系与区别,因为两者的方法并不共用,如果搞不清楚对象类型就会导致调用错误的方法. DOM(Document Object Model)称为文档 ...

  3. python实现区块链代码

    如果你明白了原理其实挺简单的. 加密算法是python自带的 需要导入hashlib import hashlib as hash sha = hasher.sha256() sha.update(' ...

  4. C语言重要概念汇总

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells Github:https://github.co ...

  5. HDOJ Oulipo 1686【KMP】

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. dede列表页调用文章,其实是所有页面都可以调用,第一次应用sql标签

    {dede:sql sql="SELECT aid,typeid,body,userip FROM `#@__addonarticle` where aid='6' or aid='7' o ...

  7. Windows 10 1703创意者更新官方ISO镜像大全

    2017年04月07日 20:00 19867 次阅读 稿源:快科技 12 条评论 Windows 10 Creators Update创意者更新正式版已经发布,目前只能通过易生.MCT工具或者ISO ...

  8. linux下开启ftp的21号port

    1.先执行vsftpd服务: #service vsftpd start 2.通过iptables开放21号port (1) 先查看iptables设置: #iptables -nL Chain IN ...

  9. IOS获取当前地理位置文本

    本文转载至  http://blog.csdn.net/lvxiangan/article/details/28101119   以下内容摘抄自网络,著作权属于原作者 方法1:使用ios自带联网查询功 ...

  10. 两个DataGridEHToExcel

    procedure TForm1.N1Click(Sender: TObject); var    GridtoExcel: TDBGridEhToExcel; begin    try    Gri ...