maximum-depth-of-binary-tree
2016-03-31 11:38
323 查看
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 binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public int maxDepth(TreeNode root) { if(root == null){ return 0; } else{ return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); } } }
相关文章推荐
- 小觅机器人sDeno亮相Nvidia发布会 发力人工智能
- GCD 定时器
- poj 2826 计算几何
- jquery 常用语法
- JavaSe基础(15)-- abstact
- java 网络编程
- Python正则表达式指南
- iis 部署 未在本地计算机上注册“Microsoft.Jet.OleDb.4.0”提供程序
- 用R语言对一个信用卡数据实现logit,GBM,knn,xgboost
- odoo列表视图下栏位宽度显示问题
- 宏定义
- Fresco 源码浅析
- java 反射机制 笔记 reflection .class
- 解压与压缩ramdisk.img文件
- sqlldr 采集中文数据乱码问题
- 记阿里巴巴的一次面试
- 《Linux内核设计与实现》第三章读书笔记
- EM及高斯混合模型
- javascript替换字符串
- 每天学点JQuery(2)—DOM操作