Java for LeetCode 104 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.
解题思路:
递归,JAVA实现如下:
public int maxDepth(TreeNode root) {
if(root==null)
return 0;
return Math.max(maxDepth(root.left), maxDepth(root.right))+1;
}
Java for LeetCode 104 Maximum Depth of Binary Tree的更多相关文章
- LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- [LeetCode] 104. Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- (二叉树 BFS DFS) leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- LeetCode 104. Maximum Depth of Binary Tree二叉树的最大深度 C++/Java
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- leetcode 104 Maximum Depth of Binary Tree ----- java
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Java [Leetcode 104]Maximum Depth of Binary Tree
题目描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...
- LeetCode 104. Maximum Depth of Binary Tree (二叉树的最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- LeetCode 104. Maximum Depth of Binary Tree
Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...
随机推荐
- 聊聊、Zookeeper Linux 单服务
关于上一篇 Zookeeper 的文章是介绍安装启动,这一篇介绍独立服务,也就是单台 Zookeeper 提供服务.首先登陆 Linux 系统,确保网络通畅.如果遇到找不到网卡 eth0 情况,可以先 ...
- Mac OS X上使用Wireshark抓包
Wireshark针对UNIX Like系统的GUI发行版界面采用的是X Window(1987年更改X版本到X11).Mac OS X在Mountain Lion之后放弃X11,取而代之的是开源的X ...
- recovery怎么刷机,recovery是什么意思
转自:http://www.3lian.com/edu/2012/04-11/25212.html Recovery是什么意思? recovery翻译过来就是“恢复”的意思,是开机后通过特殊按键组合( ...
- ImportError: cannot import name patterns
The use of patterns is deprecated in Django1.10. Therefore do not import 'patterns' and your url pat ...
- 【转】如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等
如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等 你是否曾经有过要计算一个非常大的数据(几百GB)的需求?或在里面搜索,或其它操作——一些无法并 ...
- SEO误区之——静态化页面
你随便去找一个做SEO的人或者一个公司,他百分之百会让你把网页弄成纯静态页面,然后告诉你这样对搜索引擎是如何如何地好,那么我告诉你,这个做 SEO的,肯定不专业. 网页静态化这个东西,纯属以讹传讹的事 ...
- MySQL主库异常,从库手动切换为主库方案
主库异常,从库手动切换为主库方案 1.登录从服务器,确认从服务器已经完成所有同步操作: mysql> stop slave io_thread mysql> show processlis ...
- selenium用java找到表格某一行某一列中含有特定文字的某个元素
html部分代码如下: <tbody> <tr class="odd"> <td>1609</td> <td>-YOUK ...
- AudioSession/AudioCaptureSession的分析与使用
这个是AudioSession的结构图: 前一个部分已经介绍了AVFoundation对音频录制.播放的一种方法,以下再介绍第二种: AVCaptureSession 用这个类的长处在什么地方呢? ( ...
- vue中使用key管理可复用的元素
1.概述 Vue 会尽可能高效地渲染元素,通常会复用已有元素而不是从头开始渲染. key解决上述问题之外的情景:这两个元素是完全独立的,不要复用它们. 2.示例 <!DOCTYPE html&g ...