LeetCode104_MaximumDepthofBinaryTree Java题解
题目:
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.
解题:
求最大深度 和前面一题类似 用递归遍历就能够
代码:
public static int maxDepth(TreeNode root) {
if(root==null)//递归返回或结束条件
return 0;
else {
return 1+Math.max(maxDepth(root.left),maxDepth(root.right) );
}
}
LeetCode104_MaximumDepthofBinaryTree Java题解的更多相关文章
- 【剑指offer】(第 2 版)Java 题解
[剑指offer](第 2 版)Java 题解 第一章 面试的流程 略... 第二章 面试需要的基础知识 面试题 1. 赋值运算符函数 面试题 2. 实现 Singleton 模式 Solution ...
- 试题 历届试题 核桃的数量 java题解
资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 小张是软件项目经理,他带领3个开发组.工期紧,今天都在加班呢.为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑).他的要求是: ...
- TopCoder SRMS 1 字符串处理问题 Java题解
Problem Statement Let's say you have a binary string such as the following: 011100011 One way to e ...
- LeetCode108_Convert SortedArray to BinarySearchTree(将有序数组转成二叉排序树) Java题解
题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST ...
- 7.15实习培训日志 java题解
周末总结 本周主要学习了markdown,git,docker等工具的使用.在本周的学习中,初步了解了markdown,git,docker的使用.本周的静态博客部署中,对于怎么显示一个博客内容,有两 ...
- LeetCode234_PalindromeLinkedList (推断是否为回文链表) Java题解
题目: Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) ...
- CF1256(div3 java题解)
A: 题意:给定A个N元,B个一元,问是否可以凑成S元. 思路:A*i+j=S 即 A*I<=S<=A*I+B 即min(S/N,A)+B>=S: /* @author nimphy ...
- L1-027 出租 (20 分) java题解
下面是新浪微博上曾经很火的一张图: 一时间网上一片求救声,急问这个怎么破.其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对 ...
- L1-023 输出GPLT (20 分) java题解 GPLT天梯赛防坑技巧
上题目先 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区分大小写)的个数不一定是一样多的 ...
随机推荐
- SharePoint 2013 开启訪问请求
1.通常,我们进入SharePoint 2013网站,假设没权限会提示该网站未被共享,而没有切换账号或者申请訪问,实在是非常流氓:事实上,SharePoint为我们提供了訪问请求页面.可是可能须要手动 ...
- UVA - 1471 Defense Lines 树状数组/二分
Defense Lines After the last war devastated your country, you - as the ...
- SGU 531 - Bonnie and Clyde 预处理+二分
Bonnie and Clyde Description Bonnie and Clyde are into robbing banks. This time their target is a to ...
- 根据EXCEL模板填充数据
string OutFileName = typeName+"重点源达标率" + DateTime.Now.ToString("yyyy-MM-dd"); ...
- mac下安装postgreSql
在 mac 下,可以利用 homebrew 直接安装 PostgreSQL: 1 brew install postgresql -v 稍等片刻,PostgreSQL 就安装完成.接下来就是初始数据库 ...
- Spark基本运行流程
不多说,直接上干货! Spark基本运行流程 Application program的组成 Job : 包含多个Task 组成的并行计算,跟Spark action对应. Stage : Job 的调 ...
- 爬虫概念与编程学习之如何爬取视频网站页面(用HttpClient)(二)
先看,前一期博客,理清好思路. 爬虫概念与编程学习之如何爬取网页源代码(一) 不多说,直接上代码. 编写代码 运行 <!DOCTYPE html><html><head& ...
- SQL常用函数集锦
..STUFF()用另一子串替换字符串指定位置.长度的子串.STUFF (<character_expression1>, <start_ position>, <len ...
- BZOJ4819: [Sdoi2017]新生舞会(01分数规划)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1029 Solved: 528[Submit][Status][Discuss] Descripti ...
- call使用场景
在javascript OOP中,定义: function cat(){ } cat.prototype={ food:"fish", say: funct ...