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 ...
随机推荐
- Start Developing iOS Apps Today
view types - view常见类型
- 【IntelliJ IDEA】Debug调试的使用记录
Debug调试是否能行云流水的使用,是鉴定你会不会使用一个IDE的最基本的标准. 今天再这里把Idea的debug使用流程走一遍. ================================== ...
- Qt编程简介与基本知识
1. 什么是Qt? Qt是一个基于C++的跨平台应用程序和UI开发框架.它包含一个类库,和用于跨平台开发及国际化的工具. 由挪威Trolltech公司开发,后被Nokia收购,目前被Digia公司收购 ...
- 【唯星宠物】——BootStrap/Mysql/PHP/Ajax爬坑之正则验证登录注册子页
前言:唯星宠物产品官网的登录注册,单独一个子页,页面使用BootStrap实现响应式,PHP提供服务端,利用Ajax技术,从Mysql中获取JSON数据,并对表单信息进行正则验证.项目github地址 ...
- 社区之星礼品开箱——感谢CSDN
前言 尽管已经看过国内外无数的开箱.评測视频,也看过无数国内社区的各种玩具.电子产品.摄影的分享贴.自己却从未写过--摄影水平有限以及懒-- 昨天看到上图的文章,看到最后都说了应该晒晒照片.写写博客, ...
- openssl之BIO系列之9---BIO对的创建和应用
BIO对的创建和应用 ---依据openssl doc/crypto/bio/bio_new_bio_pair.pod翻译和自己的理解写成 (作者:DragonKing Mail:wzhah@263. ...
- 2、C++ 的升级
1.内联函数 define 可以定义宏代码片段,但是,C++ 推荐使用内联函数替代宏代码片段. inline int f(int a, int b) { } 只需要在 函数定义(实现) ...
- PHP中__get()和__set()的用法实例详解
php面向对象_get(),_set()的用法 一般来说,总是把类的属性定义为private,这更符合现实的逻辑.但是,对属性的读取和赋值操作是非常频繁的,因此在PHP5中,预定义了两个函数“__ge ...
- ubuntu系统安装好后一些基本软件的安装
preface: 由于某些原因重装了系统,原来在ubuntu下安装的一些软件又要又一次安装.稍微麻烦,整理下须要安装的步骤. #==================================== ...
- 函数模板&类模板
#include <iostream> #if 0//函数模板 template<typename T> T max(T a, T b, T c)//函数模板 { if (a ...