1 /**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/
public class Solution {
/**
* @param root: The root of binary tree.
* @return: An integer.
*/
public int maxDepth(TreeNode root) {
// write your code here
if (root == null) {
return 0;
}
int left = maxDepth(root.left);
int right = maxDepth(root.right);
return Math.max(left,right) + 1;
}
}

This question I used divide and conquer to do this question. I firstly divide this into left and right subproblems and then from the leaves to root return and +1;

LintCode Maximum Depth of Binary Tree的更多相关文章

  1. [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度

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

  2. [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

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

  3. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

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

  4. LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]

    Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...

  5. 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...

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

  7. 104. Maximum Depth of Binary Tree(C++)

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

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

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

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

随机推荐

  1. js数组的一些操作

    原文地址:flash很好玩  http://www.cnblogs.com/yuzhongwusan/archive/2008/12/15/1355378.html arr = new Array(1 ...

  2. [Golang] 一个简易代理池

    晚上写了一个代理池,就是在一个代理网站上爬取代理ip和端口以及测试是否可用.接下来可能考虑扩展成一个比较大的 golang实现的代理池. 简易版代码: package main import ( &q ...

  3. HDU-4527 小明系列故事——玩转十滴水 模拟

    题意:就是平时玩的十滴水游戏,游戏者拥有一定的水滴,能够滴在某些位置,如果一个点上的体积超过了4就会爆炸,向四周传递一个小水滴.该题就是要求模拟这个过程. 分析:这里有一个问题就是不能够使用递归来处理 ...

  4. 一些常用的html/CSS效果---小技巧

    我常用的重置样式表reset.css /*===============基础信息================*/ *{border: 0;padding: 0;margin: 0;} table ...

  5. window svn链接

    我学会怎么建立window SVN服务器了 今天,终于学会怎么自己搭建SVN服务了,以前一直用的都是公司的SVN服务,没接触过,觉得很神秘,曾经我一个同事弄了好几天,也没搭成,对我打击挺大的:( 觉得 ...

  6. [分享] WIN7x64封装体积小于4G制作过程

    raymond 发表于 2015-11-1 18:27:17 https://www.itsk.com/thread-359041-1-1.html 前人栽树,后人乘凉!感谢各位大神的作品!我只是按部 ...

  7. LCT专题练习

    [bzoj2049]洞穴勘测 http://www.cnblogs.com/Sdchr/p/6188628.html 小结 (1)LCT可以方便维护树的连通性,但是图的连通性的维护貌似很麻烦. [bz ...

  8. C关键字

    1 extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义

  9. table数据表格添加checkbox进行数据进行两个表格左右移动。

    <table class="table table-hover table-striped table-condensed newDateList"> <thea ...

  10. HR函数学习01——创建组织单位

    创建组织单位: RH_OBJECT_CREATE REPORT ZLYHR01. DATA:LS_OBJ TYPE OBJEC, LV_STU TYPE GDSTR-SVECT, LV_TIT TYP ...