Maximum Depth of Binary Tree


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.

 1 /**
 2  * Definition for binary tree
 3  * public class TreeNode {
 4  *     int val;
 5  *     TreeNode left;
 6  *     TreeNode right;
 7  *     TreeNode(int x) { val = x; }
 8  * }
 9  */
10 public class Solution {
11     public int maxDepth(TreeNode root) {
12         if(root == null)
13             return 0;
14         int max_left = maxDepth(root.left);
15         int max_right = maxDepth(root.right);
16         if(max_left>max_right)
17             return max_left+1;
18         else
19             return max_right +1;
20         
21     }
22 }

优质内容筛选与推荐>>
1、rootkit hook 之[五] -- IRP Hook全家福
2、Unity Shader入门精要学习笔记 - 第7章 基础纹理
3、HDU 3111 Sudoku ( Dancing Links 精确覆盖模型 )
4、vue 页面绑定滚动事件后所有页面都会触发
5、Windows Phone里的倾斜效果 from http://www.developer.nokia.com/Community/Wiki/Windows_Phone%E9%87%8C%E7%9A%84%E5%80%BE%E6%96%9C%E6%95%88%E6%9E%9C


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号