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 ...
随机推荐
- selenium firefox46.0.1设置禁用图片
firefox_profile = webdriver.FirefoxProfile()firefox_profile.set_preference('permissions.default.ima ...
- git错误解决 -- 小结
1.今天 当我 执行 Git add somefile 的时候,出现 如下 错误: If no other git process is currently running, this prob ...
- JVM技术部分总结
1.JVM内存模型 1.1 JVM内存模型图解 Java虚拟机在执行Java程序的过程中,会把它所管理的内存划分为若干个不同的数据区.这些区域有各自的用途,以及创建和销毁的时间,有的区域随着虚拟机进程 ...
- Python批量复制和重命名文件
Python批量复制和重命名文件 示例代码 #! /usr/bin/env python # coding=utf-8 import os import shutil import time impo ...
- 利用iptables的NAT代理实现内网访问外网
利用NAT代理实现内网访问外网 背景及原理 若局域网中的两台计算机只能有一台能够访问外网,而这两台计算机之间能相互通信,那么可以配置能访问外网的那台服务器实现路由器的功能,即实现其他机器的NAT转换, ...
- IP反查网站,ip反查接口,旁站查询接口大全,通过IP查域名汇总:
http://cn.bing.com/search?q=ip%3A220.181.111.85 http://dns.aizhan.com/?q=www.baidu.com http: ...
- vue class绑定方式
1.对象语法 <div class="static" v-bind:class="{ active: isActive, 'text-danger': hasErr ...
- websocket使用ssl 证书,开启加密服务
参考文章:https://fzambia.gitbooks.io/centrifugal/content/deploy/certificates.html TLS certificates TLS/S ...
- Android后退事件的处理
当我们想退出应用程序时,一般都会采用按物理按键(后退键)的做法,当用户在按两次后退键的时候就将应用程序退出,即销毁当前的Activity(): 重写onBackPressed()方法即可: 代码如下: ...
- 初识Dubbo 系列之6-Dubbo 配置
配置 Xml配置 配置项说明 具体配置项,请參见:配置參考手冊 (+) API使用说明 假设不想使用Spring配置.而希望通过API的方式进行调用,请參见:API配置 (+) 配置使用说明 想知道怎 ...