http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/

public class Solution {
public int maxDepth(TreeNode root) {
if(root!=null){
int depth=0;
InOrder(root,depth);
}
return max; }
public int max=0;
private void InOrder(TreeNode root, int depth) {
if(root!=null){
depth++;
if(max<depth){
max=depth;
}
InOrder(root.left,depth);
InOrder(root.right,depth);
depth--;
} }
}

【LeetCode】Maximum Depth of Binary Tree的更多相关文章

  1. 【LeetCode】Maximum Depth of Binary Tree(二叉树的最大深度)

    这道题是LeetCode里的第104道题. 给出题目: 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定 ...

  2. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  3. 【Leetcode】【Easy】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】Minimum Depth of Binary Tree

    题目简述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...

  5. 【leetcode】Minimum Depth of Binary Tree (easy)

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  6. 【LeetCode练习题】Maximum Depth of Binary Tree

    Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...

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

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

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

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

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

随机推荐

  1. Sublime Text 新文本编辑器(txt3)

    http://www.sublimetext.com/

  2. AC日记——让我们异或吧 洛谷 P2420

    题目描述 异或是一种神奇的运算,大部分人把它总结成不进位加法. 在生活中…xor运算也很常见.比如,对于一个问题的回答,是为1,否为0.那么: (A是否是男生 )xor( B是否是男生)=A和B是否能 ...

  3. js对象定义的最常用的三种方法

    定义对象:属性和方法的结合体(变量和函数的结合体) 1.(***)var obj = {} 2.var obj = new Object(); 3.使用function定义对象 具体例子分别为: // ...

  4. IDEA连接linux服务器

    idea连接linux(完成了xshell和xftp连接linux的功能,可以直接卸载这俩了..) File->settings->Deployment左侧加号添加 选择传输类型ftp或者 ...

  5. Xamarin XAML语言教程对象元素的声明方式

    Xamarin XAML语言教程对象元素的声明方式 XAML的对象元素的声明有两种形式,分别为包含属性的特性语法形式以及对象元素语法形式.在1.4小节中,我们看到了其中一种对XAML对象元素的声明方式 ...

  6. ssm框架 spring的主配置文件 spring-mvc主配置文件 web.xml配置文件(基础的配置文件)

    1.spring主配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  7. laravel svn从win上传linux需要注意事项

    一首页设置目录权限: /storage  /bootstrap/cache 设置可写权限 二执行命令: php artisan key:generate

  8. Window10下Apache2.4的安装和运行

    以前用Python运行的Web框架都是要运行在Linux下,加上WSGI服务器,比如Gunicorn+Flask,后来了解到了Apache,看看能不能基于Apache这个Web服务器下给python提 ...

  9. [Guava源代码阅读笔记]-Basic Utilities篇-1

    欢迎訪问:个人博客 写该系列文章的目的是记录Guava源代码中个人感觉不错且值得借鉴的内容. 一.MoreObjects类 //MoreObjects.ToStringHelper类的toString ...

  10. chardet的使用

    http://blog.csdn.net/jy692405180/article/details/52496599