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. select、poll和epoll的区别(转载)

    select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作.但select ...

  2. js-触屏滑动判断滑动方向(移动版)

    var startx, starty; //获得角度 function getAngle(angx, angy) {     return Math.atan2(angy, angx) * 180 / ...

  3. python 中各种数据类型的排序问题

    list #按照list的第二键值排序 disP2P = [[1,2,3],[2,3,4],[4,5,6]] disP2P = sorted(disP2P,key = lambda x:x[2]) s ...

  4. guava之cache

    转自:http://ifeve.com/google-guava-cachesexplained/ 范例 01 LoadingCache<Key, Graph> graphs = Cach ...

  5. java性能监控工具jps-windows

    jps Lists the instrumented Java Virtual Machines (JVMs) on the target system. This command is experi ...

  6. vue2.0 自定义过滤器

    2.0中已经废弃了过滤器,需要我们自定义 <div id="app"> {{message|uppercase}} </div> //过滤器 Vue.fil ...

  7. xpages很不错的demo

    之前有上传了xpages的样例,如今统一把地址发出来,希望对学习xpages的朋友有帮助 1)这是主要的教程,在没有扩展库之前的教程,假设能熟练使用这个样例已经够了,加上你有html,js,css的功 ...

  8. mysql freeing items 状态

    http://blog.sina.com.cn/s/blog_6128a8f00100wsdd.html数据库出现大量的freeing items状态 表更新慢 而且大量锁表查看mysql官方free ...

  9. mysql 海量数据删除

    百度知道 - mysql删除海量数据   MySQL 数据库删除大批量数据的优化     看到这儿的话,最后看下这篇文章,对于操作海量数据的sql深入分析 cnblogs - 深度分析DROP,TRU ...

  10. x264 编码数配置

    记录项目中用到一组x264快速编码参数配置,具体如下: param->i_frame_reference = 1; param->i_scenecut_threshold = 0; par ...