LeetCode OJ 104. Maximum Depth of Binary Tree
2016-04-25 20:36
302 查看
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.
很简单,直接上代码:
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
很简单,直接上代码:
/** * Definition for a binary tree node. * 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; int leftmax = maxDepth(root.left); int rightmax = maxDepth(root.right); return leftmax>rightmax?leftmax+1:rightmax+1; } }
相关文章推荐
- C语言中不同变量的访问方式
- poj3579 Median
- docker容器网络通信原理分析
- (2.2.10)Gradle 介绍
- 冲刺阶段第七天
- 第一冲刺阶段(第四天)
- Android Studio中关联源码(source for Android API)的方法
- iOS设计模式
- (2.2.9.4)grovy脚本类、文件 I/O 和 XML 操作
- Python - decorator
- LeetCode *** 210. Course Schedule II
- TCP协议详解
- 并行、并发、同步和互斥
- 采用dom实现复选框全选、取消效果
- HDU-1087 Super Jumping! Jumping! Jumping!( DP )
- ElasticSearch Search API 简介
- render用法
- Solr安装笔记
- mysql基础(三)
- 科技辅导员,信息化助力成长